我有一个页面,它将XMLHttpRequest调用到另一个站点的页面。问题是,返回的状态是0。 来电者页面的代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Generator" content="Dev-PHP 2.6.0" />
<meta name="Keywords" content="your,keywords,here" />
<meta name="Description" content="." />
</head>
<body>
<p>
<input type="text" name="txtReturn" id="txtReturn" size=75 />
</p>
<textarea name="taStatus" id="taStatus" cols="75" rows="25"></textarea>
<p> </p>
<script type="text/javascript">
function getReturn()
{
var txtBox = document.getElementById("txtReturn");
var taStatus = document.getElementById("taStatus");
txtBox.value = "Preparing to get Response";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
// alert('IE7+, Firefox, Chrome, Opera, Safari');
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
// alert('IE6, IE5');
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
taStatus.innerHTML = taStatus.innerHTML + "URL: " + url + ".\nReadyStatus: " + xmlhttp.readyState + ".\nStatus: " + xmlhttp.status + ".\nStatusText: " + xmlhttp.statusText + ".\nresponseText: " + xmlhttp.responseText + ".\n\n";
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// alert(xmlhttp.responseText);
txtBox.value = xmlhttp.responseText;
// alert(xmlhttp.responseText);
}
}
var url = 'http://www.ip.com.om/site/checkdata.php';
var url2 = 'http://badihbarakat.com/site/checkdata.php';
var url3 = '../site/checkdata.php';
xmlhttp.withCredentials = true;
// url = url + ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
getReturn();
</script>
</body>
</html>
另一个网站上的.php页面,只是回显一个带有日期和时间的字符串。
任何人都可以建议可能出现的问题吗?我正在使用FireFox 27,我已经检查了错误浏览器,它显示:
**GET http://www.ip.com.om/site/checkdata.php [HTTP/1.1 200 OK 710ms]**
当您点击它时,请求的详细信息显示:
Request URL: http://www.ip.com.om/site/checkdata.php
Request Method: GET
Status Code: HTTP/1.1 200 OK
**Request Headers 17:27:37.000**
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Referer: http://badihbarakat.com/local/
Origin: http://badihbarakat.com
Host: www.ip.com.om
Connection: keep-alive
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
**Response Headers Δ710ms**
X-Powered-By: PHP/5.3.26
X-CFLO-Cache-Result: TCP_REFRESH_MISS
Server: Apache
Date: Sat, 01 Mar 2014 13:27:42 GMT
Content-Type: text/html
Content-Length: 37
Connection: Keep-Alive
Age: 0
等待您的宝贵回复......
Badih Barakat
答案 0 :(得分:0)
由于安全问题,您无法对其他域中的服务器执行xmlhttp请求。 您可以从服务器端代码使用服务,然后可以通过您自己的服务将其代理到页面。 查看以下帖子。 Still confused about using XMLHTTPRequest cross domain