Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax Not Loading Asynchronous. Refreshing Page when form submitted
    primarykey
    data
    text
    <p>I have been trying to learn ajax and from what I can see my code is correct however it always refreshes the page when it echo's the returned json string. Any help would be greatly appreciated!</p> <pre><code> &lt;script&gt; // Get XML HTTP Type function get_XmlHttp() { var xmlHttp = null; if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); }else if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlHttp; } function ajaxSuccess () { alert(this.responseText); } function ajaxrequest(oFormElement) { //Get The Correct XMLHTTP Object var request = new XMLHttpRequest(); request.open(oFormElement.method, oFormElement.action, true); request.setRequestHeader("Content-type","application/x-www-form-urlencoded"); request.send(new FormData(oFormElement)); return false; request.onreadystatechange = function() { if (request.readyState == 4 &amp;&amp; request.status == 200) { alert("done"); document.getElementById('comment_form').innerHTML = request.responseText; } } } &lt;/script&gt; &lt;form action="&lt;?php echo $add_comment; ?&gt;" method="post" enctype="multipart/form-data" id="comment_form" onsubmit="ajaxrequest(this);"&gt; &lt;input name="user_id" type="hidden" value="&lt;?php echo $user_id; ?&gt;"&gt; &lt;input name="user_message_id" type="hidden" value="&lt;?php echo $user_message_id; ?&gt;"&gt; &lt;textarea id="new_comment" name="new_comment" cols="100" rows="5"&gt;&lt;/textarea&gt; &lt;input type="submit" value="post request"/&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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