[英]XMLHttpRequest object status code of 0
I have a Javascript function using an XMLHttpRequest object, but the status I keep getting returned is 0. I've done lots of searching, and all I've come up with is that 0 is an undefined error and can be caused by a myriad of reasons. 我有一个使用XMLHttpRequest对象的Javascript函数,但是我一直返回的状态是0。我已经做了很多搜索,而我所想的只是0是一个不确定的错误,可能是由无数的原因引起的。原因。 As such, I'm hoping you guys can spot the error in my code.
因此,我希望你们能在我的代码中发现错误。
function initiateIPP(ID, Token)
{
var POSTRequest = new XMLHttpRequest();
POSTRequest.onreadystatechange = function ()
{
if (POSTRequest.readyState == 4)
{
if (POSTRequest.status == 200)
{
}
else
{
alert("An error has occured, response code = " + POSTRequest.status);
}
}
}
var parameters = "SessionId=" + ID + "&SST=" + Token;
POSTRequest.open("POST", "https://demo.ippayments.com.au/access/index.aspx", true)
POSTRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
POSTRequest.send(parameters)
window.open("IPPPage.html");
}
Thanks in advance. 提前致谢。
EDIT: I added a withCredentials line to my code but that doesn't seem to have made a difference. 编辑:我在代码中添加了一个withCredentials行,但这似乎没有什么不同。 var parameters = "SessionId=" + ID + "&SST=" + Token;
var parameters =“ SessionId =” + ID +“&SST =” +令牌; POSTRequest.withCredentials = true;
POSTRequest.withCredentials = true; POSTRequest.open("POST", " https://demo.ippayments.com.au/access/index.aspx ", true) POSTRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded") POSTRequest.send(parameters) window.open("IPPPage.html");
POSTRequest.open(“ POST”,“ https://demo.ippayments.com.au/access/index.aspx ”,true)POSTRequest.setRequestHeader(“ Content-type”,“ application / x-www-form-urlencoded “)POSTRequest.send(parameters)window.open(” IPPPage.html“);
" https://demo.ippayments.com.au/access/index.aspx " this should be same domain with your javascript, otherwise, you should set : “ https://demo.ippayments.com.au/access/index.aspx ”,该域应该与您的JavaScript相同,否则,您应该设置:
Access-Control-Allow-Origin: *
on target page's response header to get work. 在目标页面的响应标题上进行操作。 See http://enable-cors.org/
参见http://enable-cors.org/
For example you can put below in web.config on target server : 例如,您可以在目标服务器上的web.config中放置以下内容:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
To integrated properly with the IPPayments page at https://demo.ippayments.com.au/access/index.aspx , you need to use the Direct Post method. 要与https://demo.ippayments.com.au/access/index.aspx上的IPPayments页面正确集成,您需要使用直接过帐方法。 Instead of using the XMLHttpRequest object, use a HTML form to submit the ID and token.
代替使用XMLHttpRequest对象,而使用HTML表单提交ID和令牌。 For example -
例如 -
<form action="https://demo.ippayments.com.au/access/index.aspx" method="post">
<input type="hidden" name="SST" value="1243123123123123123"/>
<input type="hidden" name="SessionID" value="53535434535345"/>
<input type="submit" value="submit" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.