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. 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. var parameters = "SessionId=" + ID + "&SST=" + Token; 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");

5
  • Does this helps.. stackoverflow.com/questions/2752657/… Commented Mar 14, 2015 at 5:58
  • I did come across the issue of different origins... it could be the problem, I'm not sure, but if it is I'm not sure if it's really feasible to do something about it. Maybe I have to ask IPP how they expect me to send data to them... Commented Mar 14, 2015 at 6:03
  • If you are facing Cross Origin Resource issue, you probably should run using some server, could be apache, or another way would be to set --disable-web-security flag to your chrome browser... Commented Mar 14, 2015 at 6:09
  • @Rakesh_Kumar --disable-web-security will only solve the issue for him. Commented Mar 14, 2015 at 6:16
  • Exactly, @gabeio is correct; this needs to work WITHOUT forcing people to go fiddling with settings in their browser. Commented Mar 14, 2015 at 6:29

2 Answers 2

2

"https://demo.ippayments.com.au/access/index.aspx" this should be same domain with your javascript, otherwise, you should set :

Access-Control-Allow-Origin: *

on target page's response header to get work. See http://enable-cors.org/

For example you can put below in web.config on target server:

<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>
</configuration>
Sign up to request clarification or add additional context in comments.

18 Comments

Wait a sec, you're saying I need to set something in the other page's response header? How? o_O
@MichaelSmith for that you should search about settings response headers from your server
@MichaelSmith I see you use aspx, so I guess you can set in web.config.
Adding that to web.config hasn't helped. :(
Yeah then the issue is you need to tell them to allow what AndyChen is saying.
|
0

To integrated properly with the IPPayments page at https://demo.ippayments.com.au/access/index.aspx, you need to use the Direct Post method. Instead of using the XMLHttpRequest object, use a HTML form to submit the ID and token. 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>

1 Comment

What I ended up doing was doing everything in the code-behind (this is an ASP.NET application/website) and just encoding the SessionID and SST as GET parameters and redirecting to the page that way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.