Javascript 我的代码在xampp中工作,但在000webhost.com上不工作
当我在localhost上测试它时,它工作正常,但当我在网站“000webhost.com”上使用它时,控制台会写“坏!”(就像在代码中一样)。我不知道为什么它在localhost上工作,为什么不在000webhost.com上工作 这是我的ajax:Javascript 我的代码在xampp中工作,但在000webhost.com上不工作,javascript,php,json,Javascript,Php,Json,当我在localhost上测试它时,它工作正常,但当我在网站“000webhost.com”上使用它时,控制台会写“坏!”(就像在代码中一样)。我不知道为什么它在localhost上工作,为什么不在000webhost.com上工作 这是我的ajax: var xmlhttp = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatecha
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();
这是我的php:
//$content is html code ex: <span>I'm here</span>
$resp = array(
'r' => true,
'response' => $content,
);
echo json_encode($resp);
/$内容是html代码示例:我在这里
$resp=数组(
'r'=>正确,
“响应”=>$content,
);
echo json_编码($resp);
当我删除
try
时,会产生错误意外标记请确保在OPEN方法中传递URL,这是代码中唯一的内容您知道吗?从错误的声音来看,您的JSON似乎无效。记录异常e
:console.Log(e)代码>语法错误消息:“意外的标记听起来像你的JSON是无效的。你尝试过吗?OMG:)我尝试过console.log(respText);
并且有000webhost.com广告。我想我需要die
在php中。我将作为答案发布。