Note that there are some explanatory texts on larger screens.

plurals
  1. POHttp response 0 for Ajax call from Javascript
    primarykey
    data
    text
    <p>I am trying to do an AJAX call (POST) to the the php page which is in the same folder as my javascript. I am getting <code>http.status = 0</code> and <code>http.readyState = 4</code> </p> <p>This is the js code:</p> <pre><code>var http = new XMLHttpRequest(); var url = "processor.php"; var params = "processad=ipsum&amp;name=binny"; http.open("POST", url, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() {//Call a function when the state changes. alert("status: " + http.status); alert("ready state: " + http.readyState); if(http.readyState == 4 &amp;&amp; http.status == 200) { alert(http.responseText); } } http.send(params); </code></pre> <p>and this is php code</p> <pre><code>if (isset($_POST['processad'])) { echo "reads"; } </code></pre> <p>I can figure out what is wrong here. Both files(js and php) are in the same folder, and the path for php file is relative. Not sure what am I doing wrong. Thanks in advance!</p> <p>Addition: </p> <pre><code>HTTP request looks like this Request URL:http://as.cbothemes.com/ads_script/processor.php Request Headersview source Cache-Control:no-cache Content-type:application/x-www-form-urlencoded Origin:http://as.cbothemes.com Pragma:no-cache Referer:http:_/_/_as.cbothemes.com/ads_script/12.html?i=100&amp;j=12&amp;cb=1367948759088 User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31 Form Dataview sourceview URL encoded processad:ipsum name:binny </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.
 

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