In a jQuery AJAX post, is it possible for the data payload not to be sent?
I have a problem where sometimes the data payload in the AJAX code below is not sent to the server.
// loans_url, sample_id, sample defined above this block
$.ajax({
type: "POST",
url: loans_url,
data: {'loan[sample_id]':sample_id},
beforeSend: function() { sample.remove(); },
success: function(data) { $('#basket table tr:last').after(data); },
error: function() { $('#results').prepend("Apologetic error message..."); }
});
A "good" post sends data looking like this: loan[sample_id]: 1234
. A "bad" post hits the correct URL but does not send any data at all.
I cannot reproduce this in development yet it happens about once a day in production. In Firebug I tried sabotaging the markup in the page from which sample_id is obtained, but that simply caused loan[sample_id]: undefined
to be sent, which is not the problem I am facing.
Is there any way the data payload could be not sent at all? Can you suggest how I might debug this further? (This is all 开发者_开发知识库with jQuery 1.3.2.)
Try to define a error
handler for your jquery ajax call and log the error data somewhere (uh, probably make another ajax call to a error logger?) If it's a connectivity issue it will be much more difficult to log anything remotely. Depending on your app, you may want to log something locally (cookies maybe) for posterior analysis (once the connection is up, assuming its a connectivity issue).
The post data would only be lost if there was a connectivity issue - for example, you could replicate this by pulling your network cable out just as your press "Submit" - the headers MIGHT make it, the post data MIGHT not - the headers are always sent first.
So, I think you're looking at infrastructure. A lost internet connection, some missing packets or something similar. I don't think that's a problem for a developer to solve - just as long as you only accept fully formed post requests.
精彩评论