when i test it on localhost it works fine but when i use it on website "000webhost.com" console writes "BAD!" (as it is in code). I have no idea about why it is working on localhost and why not on 000webhost.com
There is my ajax:
var xmlhttp = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var respText = xmlhttp.responseText;
try{
var json = JSON.parse(respText);
console.log("GOOD!");
}
catch(e){
console.log("BAD!");
}
}
}
xmlhttp.open(method,url + "?" + parameters,true);
xmlhttp.send();
There is my php:
//$content is html code ex: <span>I'm here</span>
$resp = array(
'r' => true,
'response' => $content,
);
echo json_encode($resp);
When i delete try
it makes error unexpected token <
Sorry for my English and thank you for helping.
Have you checked your JSON ? By the sounds of the error, it sounds like your JSON is invalid.
确保通过OPEN方法中的URL,这是代码中唯一的事情
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.