Javascript Ajax调用始终返回readyState=1和status=0
我通过AJAX发送post请求,如下所示 我总是得到xmlhttp.readyState=1和xmlhttp.status=0。xmlhttp.responseText始终为空 你能告诉我有什么问题吗 我希望xmlhttp.readyState==4&&xmlhttp.status==200 HTML部分Javascript Ajax调用始终返回readyState=1和status=0,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我通过AJAX发送post请求,如下所示 我总是得到xmlhttp.readyState=1和xmlhttp.status=0。xmlhttp.responseText始终为空 你能告诉我有什么问题吗 我希望xmlhttp.readyState==4&&xmlhttp.status==200 HTML部分 您需要添加一个var作为xmlhttp;在开始获取状态结果时,请使用下面的代码进行修改 <script> //Ajax to send request.. function sen
您需要添加一个var作为xmlhttp;在开始获取状态结果时,请使用下面的代码进行修改
<script>
//Ajax to send request..
function sendPayment()
{
var xmlhttp;
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>
如果您正在呼叫您自己的另一个站点,您必须在您的另一个站点ie中授予访问权限 把这个标题放在你的 对于特定页面
header('Access-Control-Allow-Origin: http://www.yourxmlrequestpage.php');
希望这有帮助
谢谢成功警报是否从未显示?xmlhttp.readyState始终返回true,ajax始终返回值。请指定您的ajax状态result@adeneo:是的。虽然我在/callSSL.php文件中发送了一些输出,但我得到的结果是空的检查您的callSSL.php,您必须回显而不返回您的结果您不能从另一个域调用检查相同的结果。。没用。。我使用了许多ajax请求,但我没有将其全部指定为varAdd xmlHttpRequest.send;在xmlHttpRequest.onreadystatechange=processRequest;之后;。请尝试此选项,可能会对您有所帮助。请与“var xmlhttp;”一起使用希望获得此帮助或确保它是processRequest函数。如果您担心,请将上面的*替换为发送xmlhttp请求的页面url。上述编辑将避免安全漏洞。让我知道你的身份
<script>
//Ajax to send request..
function sendPayment()
{
var xmlhttp;
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>
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Origin: http://www.yourxmlrequestpage.php');