[英]XMLHttpRequest object status code of 0
我有一個使用XMLHttpRequest對象的Javascript函數,但是我一直返回的狀態是0。我已經做了很多搜索,而我所想的只是0是一個不確定的錯誤,可能是由無數的原因引起的。原因。 因此,我希望你們能在我的代碼中發現錯誤。
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");
}
提前致謝。
編輯:我在代碼中添加了一個withCredentials行,但這似乎沒有什么不同。 var parameters =“ SessionId =” + ID +“&SST =” +令牌; 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“);
“ https://demo.ippayments.com.au/access/index.aspx ”,該域應該與您的JavaScript相同,否則,您應該設置:
Access-Control-Allow-Origin: *
在目標頁面的響應標題上進行操作。 參見http://enable-cors.org/
例如,您可以在目標服務器上的web.config中放置以下內容:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
要與https://demo.ippayments.com.au/access/index.aspx上的IPPayments頁面正確集成,您需要使用直接過帳方法。 代替使用XMLHttpRequest對象,而使用HTML表單提交ID和令牌。 例如 -
<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.