0

I'm having a serious problem with an ajax post not sending any request intermittently.

In my script I first place a getJson request to my own server to create a database entry. This never fails:

jQuery.getJSON("/counter/placeorder", function(json) {
    var txndatetime     = json.txndatetime;
    var hash            = json.hash;
    ...

With some values returned via JSON from my server I then try to send an ajax post request to a foreign server.

    $.ajax({    url: "https://www.someserver.com/processing",
        type: "POST",
        data: {
            'txndatetime': txndatetime,
            'hash': hash,
            ...
        },
        complete: function(xmlHttp, status) {
            window.location = '/counter/exit';
        }
    });     

But the problem lies not with the foreign server. I wrapped the ajax post in another ajax post in which I tried to send the same request to another debugging server first and sometimes there doesn't seem to be a post request at all.

If however I serialize the data and put that in my debugging post request's url, then this does get sent to my debugging server while the following post to the actual processing server does not fire. This would hint at a problem with the retrieved data from the getJSON, but the data is identical in form to the requests that do work.

The only idea I'm left with is that this might be a time out issue with the JSON. Any ideas?

  • 2
    You should get Firebug or some other debugger and watch what is actually sent to the server. Might reveal the problem. – MightyPork Aug 01 '13 at 18:30
  • And you're sure it's not a same origin issue? What's the point of doing an ajax request when you always redirect anyway ? – adeneo Aug 01 '13 at 18:30
  • MightyPork: The trouble is that it is always working for me. I posted A LOT of credit card orders and all went through. The problem is that sometimes inexplicably customer orders don't go through. – submnml Aug 01 '13 at 18:36
  • adeneo: The reason for the ajax request is that I need to get the data as post data to the receiving server. They in turn call a notification url (on my server) which parses the result. My post to their server is not graced with a result though, I always get an error back, regardless of the actual transaction result. That's why I use the complete section to redirect to the exit on my site. Also, the whole thing sometimes does work and sometimes it doesn't. And the data submitted looks most inconspicous in each case. – submnml Aug 01 '13 at 18:38

1 Answers1

0

I've finally solved my problem by creating a second form, adding hidden input fields via jquery and then submitting this. Apparently there's a difference in the order at which elements of the code are executed and maybe the ajax request fired prematurely every now and then, but at any rate with the form sbmit it works every time.