Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmitting form in php file accessed by Ajax?
    text
    copied!<p>I am trying to figure out how to submit a form in a page being accessed by Ajax?</p> <p>here are some code snippets to help demonstrate what i am trying to say.</p> <p><strong>HTML BODY - THIS IS WHAT THE USER WILL SEE.</strong></p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;script language="javascript" src="linktoajaxfile.js"&gt; &lt;/head&gt; &lt;body onLoad="gotoPage(0)"&gt; &lt;div id="fillThis"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>AJAX FILE</strong></p> <pre><code>var xmlhttp function gotoPage(phase) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="pageofstuffce.php"; url=url+"?stg="+phase; url=url+"&amp;sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("fillThis").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </code></pre> <p><strong>PAGE OF DATA</strong></p> <pre><code>&lt;?php $stage = $_GET['stg']; if($stage == 0) { echo '&lt;a onClick="gotoPage(1)"&gt;click me&lt;/a&gt;'; } elseif($stage == 1) { &lt;form&gt; &lt;input type="text" name="name"&gt; &lt;input type="submit" name="submit"&gt; &lt;/form&gt; } elseif(somehow can reach here) { show data from form. } ?&gt; </code></pre> <p>Can anyone perhaps help me get past the form and display the data in the same page? Also, i have looked around, and i don't think anything around has what i need... correct me if i'm wrong though :)</p> <p>Thanks in advance, and i hope i didn't put in too much detail :) Dronnoc</p> <p><strong>EDIT</strong><br> Forgot to mention what I've tried; I have tried submitting the form to itself (same file) and that destroyed the ajax link, and opened the page. i have also tried just having the button move the page onto another step, but the $_POST variable is empty... i am at a loss, so does anyone else have any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload