我试图从PHP的Web服务在JavaScript中的http响应,但在Firefox和Chrome中得到空。 PLZ告诉我,我在这里做的错误是我的代码,问题在获取Http响应在铬
function fetch_details()
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest()
alert("first");
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP")
alert("sec");
}
xhttp.open("GET","url.com",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;
alert(xmlDoc.getElementsByTagName("Inbox")[0].childNodes[0].nodeValue);
}
我曾尝试与阿贾克斯还,但我不是在这里得到的HTTP响应是我的代码,请指导我
var xmlhttp = null;
var url = "url.com";
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
alert(xmlhttp); //make sure that Browser supports overrideMimeType
if (typeof xmlhttp.overrideMimeType != 'undefined')
{
xmlhttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert('Perhaps your browser does not support xmlhttprequests?');
}
xmlhttp.open('GET', url, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseXML);
}
};
}
//进行实际的请求 xmlhttp.send(null);
我越来越xmlhttp.readyState = 4 xmlhttp.status = 0 xmlhttp.responseText = “”
PLZ告诉我在哪里,我在做错误
请你谈谈你的代码格式。文本字段上方有一个“010101”按钮,用于将代码标记为代码。即使我为你点击它,这个代码仍然太杂乱,所以这次我不打扰。 – deceze 2010-04-05 06:32:46
您是否在提出跨域请求?这是一个常见的情况下得到的状态代码为0. – Anurag 2010-04-05 07:58:20