tags:

views:

81

answers:

1

I have a simple 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?

+1  A: 

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.

Farhadi
thanks! message boards and the like other than stackoverflow scare me :-) you might want to add that success is called when submit is called - just in case it isn't the exact same trigger
Simon_Weaver
behavior different in different browsers too
Simon_Weaver