views:

39

answers:

1

Hi,

I have got a test page to use Ajax to make a http 'delete' request to a server. The following JS code works as intended in IE7, but it does not work in Firefox (unless I make the ajax call asynchronous).

In Firefox, unless async is false, the error callback gets triggered with status of 0.

  1. Can anyone assist in explaining why this is apparently working in Firefox if the call is synchronous?
  2. In the context of this page, a synchronous call is not a bad thing, however I have read that this should be avoided as this would effectively freeze the browser window until the response had returned. Is there an alternative solution anyone can suggest?

The relevant code is below:-

<script src="${url.context}/scripts/jquery-1.3.2.min.js"></script>

<SCRIPT LANGUAGE="JavaScript">

jQuery.noConflict();

function deleteImage(nodeParam) {
      alert('hello');
      var options = {
        type: 'DELETE',
  async: false,
        url: '${url.context}/service/api/asset/delete?alf_ticket=${session.ticket}'+'&format=text'+'&'+nodeParam,
        dataType: 'json',
        success: function(data, textStatus) {
          jQuery('#result-div').html('');
          if (data['ok'] == true) {
            //jQuery('#result-div').html('Delete successful using parameter - ' + nodeParam);
            alert("Delete successful" );
          } else {
            alert( "Response 'ok' set to 'false' on success callback!" );
            jQuery('#result-div').html('Delete failed!');
          }
        },
        error: function (request, textStatus, errorThrown) {
          //jQuery('#result-div').html('Delete failed!');
    alert("Delete Failed");
    alert(request.status);
          //alert("Error callback triggered, request failed with status: " + request.status + ' ' + request.responseText);
        }
      };
      jQuery.ajax(options);
}
// End -->
</script>

Thanks J

A: 

Firefox doesn't call onreadystatechange for synchronous requests, so jQuery may fail to call your custom callback because of that. Otherwise it is generally bad idea to make sync requests.

Sergey Ilinsky
Can you clarify this? What you are saying is that onreadystate change being called is inhibiting the callback from being fired. I note that everything works when async=false.
Jamen