我对JavaScript知之甚少,但已经设法在我的网站上为ajax请求组装代码,但现在发现它仅适用于Mozilla/Firefox。 我的代码是:Mozilla接受的XMLHTTPRequest在其他浏览器中被拒绝
function ajaxFunction(char){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
if(this.status !==200){
**alert("Error: Status '+this.status+' returned.");**
}else{
document.getElementById('directory').innerHTML= ajaxRequest.responseText;
}
}
}
var namevalue=char
ajaxRequest.open("GET", "../directory pagtestAug.php?name="+namevalue, true);
ajaxRequest.send(null);
}
我也利用的: SRC = “// ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js”>
(虽然我不确定这是什么 - 我发现很难找到超出最基本的JavaScript学费)
响应是错误:状态'+ this.status +'返回。
我在200状态中看过很多帖子,但没有看到如果服务器没有响应该怎么办。是否有其他代码可供使用,或者每个浏览器有不同的代码? 感谢您不辞劳苦地阅读本(与回复,请)
既然你有jQuery,我建议看看['.ajax()'](http://api.jquery.com/jquery.ajax/)。 – imtheman
那些'**'是什么?你是否试图评论该行? – Knu
您在报警上的报价不匹配。更改为“错误:状态”+ this.status +“返回”。实际得到一个状态码。 –