A simple ajax question

I need to send mail before sending my php page, I send the page using javascript. my mail script is in the sendmails.php file. so can i send an ajax request to send mail before sending the page using java script? well

function submit_page()
{
//trying to run send_mail.php
..............................//ajax codes
............................
xmlhttp.open("GET","send_mail.php",true);
xmlhttp.send();
.................................

if(a)
form.action = 'one.php'
else
form.action = 'two.php'
form.submit()//form submitting using javascript
}

Will send_mail.php be launched on the server?

thank

+3
source share
2 answers

Yes, but do not rely on this happening before returning send(). send()just starting a background thread that will eventually open a connection to send_mail.phpand publish the form. It may happen that the form is submitted before the mail is sent.

+2
source

- ajax , , .

- ajax . , , .

0

Source: https://habr.com/ru/post/1770890/


All Articles