I am using pure javascript to make an ajax call to a PHP file which is residing in the remote server . But it is not returning the response.
The page which is making the ajax call is in my localhost .
Here is the ajax call code:
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
if(xmlhttp.responseText == 1){
document.getElementById("update").innerHTML = "Update Successfull";
}
}
}
//https://flo2go-airteliptv.rhcloud.com
xmlhttp.open("POST",'https://xyz.com/purchasereturn.php',true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("setflag=1");
The PHP code on the remote server is this:
<?php
header('content-type: application/javascript; charset=utf-8');
$purchasevalue = 0;
while($purchasevalue != 1){
$query = "SELECT * FROM purchase WHERE purchase_id = 1";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$purchasevalue = $row['purchase_flag'];
}
}
//$purchasevalue = "{purchase:$purchasevalue}";
echo $purchasevalue;
?>
How can I get the response ? Please help.
你为什么要问if(xmlhttp.responseText == 1){
xmlhttp.responseText是实际的响应,我看到你返回的是json,所以它永远不会返回1,所以永远不会进入if
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.