gpt4 book ai didi

Javascript Ajax 调用始终返回readyState=1 和status=0

转载 作者:行者123 更新时间:2023-12-03 12:13:33 25 4
gpt4 key购买 nike

我通过 AJAX 发送 POST 请求,如下所示。

我总是得到 xmlhttp.readyState = 1xmlhttp.status= 0xmlhttp.responseText 始终

您能告诉我可能是什么问题吗?

I expect xmlhttp.readyState==4 && xmlhttp.status==200

<script>
//Ajax to send request..
function sendPayment()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
alert(xmlhttp.readyState);// this always returns = 1
alert(xmlhttp.responseText) ; //this is always empty.
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText=='1')
{
alert('success');
}
}
}
xmlhttp.open("POST","payments/callSSL.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(Id=100);
return false;
}
</script>

HTML 部分

<input name="button" type="submit" id="button" value="Confirm" onclick="sendPayment()" />

最佳答案

如果您要调用自己的另一个站点,则必须在您的另一个站点(即( http://my-other-site.com/payments/callSSL.php )中授予访问权限。

将此 header 放入您的 http://my-other-site.com/payments/callSSL.php

header('Access-Control-Allow-Origin: *'); 

针对特定页面

header('Access-Control-Allow-Origin: http://www.yourxmlrequestpage.php');

希望这有帮助,

谢谢

关于Javascript Ajax 调用始终返回readyState=1 和status=0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837172/

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