D
Duaa Momani
Guest
Usually, we create a form in HTML and define the JS function that will handle the form and send the information by AJAX to the PHP page e.g:
<form>
elements here...
<button onclick="handle();">Submit</button>
</form>
where handle() is a javascript function that sends the form data in an HTTPrequest to the PHP.
My question is, what if I need to do the opposite way and return a form in the AJAX response. e.g:
main.html contains this javascript code:
xhr.open('a.php');
....
document.getElementById('div').innerHTML=xhr.responseText;
and a.php contains:
<form>
elements here...
</form>
then, were should I submit the form? I tried submitting it to a.php ,or the main page that calls a.php and both didn't work..
what should I do in this case?
<form>
elements here...
<button onclick="handle();">Submit</button>
</form>
where handle() is a javascript function that sends the form data in an HTTPrequest to the PHP.
My question is, what if I need to do the opposite way and return a form in the AJAX response. e.g:
main.html contains this javascript code:
xhr.open('a.php');
....
document.getElementById('div').innerHTML=xhr.responseText;
and a.php contains:
<form>
elements here...
</form>
then, were should I submit the form? I tried submitting it to a.php ,or the main page that calls a.php and both didn't work..
what should I do in this case?