gpt4 book ai didi

javascript - 跨站点 xmlhttp 请求返回状态 0

转载 作者:行者123 更新时间:2023-11-28 08:28:41 25 4
gpt4 key购买 nike

我有一个页面,它从另一个站点调用 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>&nbsp; </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

等待您的宝贵回复...

巴迪巴拉卡特

最佳答案

由于安全问题,您无法向不同域中的服务器发出 xmlhttp 请求。您可以从服务器端代码使用该服务,然后可以通过您自己的服务将其代理到页面。检查以下帖子。 Still confused about using XMLHTTPRequest cross domain

关于javascript - 跨站点 xmlhttp 请求返回状态 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22115028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com