I have a simple开发者_如何学Python AJAX jQuery command to update a shopping cart (triggered by a dropdown list box change):
$.ajax({
type: "POST",
url: $.url("updateCart"),
data: data,
dataType: "json",
success: function (data, status, req) {
alert(data + " - " + status + " - " + req);
});
It appears that in jQuery 1.4.x the calling behavior of the success
callback changed.
If you submit an AJAX query and then click a 'regular' HTML Form submit button it will instantly send 'null' to the success callback. So for the above example if i trigger the AJAX event and then click a non-AJAX submit button - it displays an alert :
null - success - [object XMLHttpRequest]
Fiddler is verifying for me that the AJAX response has not yet come back from the server - yet the success
method is called.
This was breaking some of my code because it expected data to exist.
I'm fine checking for null
if I have to - I just cannot find any documentation on this change in jQuery.
So I'm wondering is this a bug or by design?
I think it's a bug and I filled a ticket in jQuery bug tracker for it. (http://dev.jquery.com/ticket/6172)
This bug does not exist in jQuery 1.4.0 and earlier.
精彩评论