Robert
Robert

Reputation: 5302

ajax inconsistent on Safari

-EDIT-

I have tried to add some error handling to the failing function with error: function(jqXhr, status, error) but jqXhr.responseText is empty so I guess I'm still not handling errors properly.

-/EDIT-

I am new to ajax and have to modify an existing site with these two existing ajax functions, both of which are working fine in Chrome, IE and FF but only the first works in Safari. The second one fails but the error handler (which I guess wasn't set up properly?) doesn't tell me much:

// works in each browser
$.ajax({
    cache: false,
    type: 'GET',
    url: apiBaseUrl + 'GetCountries',
    dataType: 'xml',
    success: parseCountries,
    error: function(){
        $('.errorMessage').append('<p>' + errorMessage + '</p>');
    }
});

// does not work in Safari
$.ajax({
    cache: false,
    type: 'GET',
    url: apiBaseUrl + 'GetStandardTexts?page=login',
    dataType: 'xml',
    success: displayRegisteredAlert,
    error: function(jqXhr, status, error){
        var err = eval("(" + jqXhr.responseText + ")"); 
        alert(err.Message);    
    }  
});

the only real difference between them that I can see is the URL in the second contains and additional parameter, ?page=login.

Upvotes: 0

Views: 855

Answers (1)

Robert
Robert

Reputation: 5302

I finally got this to work. I'm not entirely sure why but adding async:false solved it for Safari. Not required for other browsers.

$.ajax({
    async: false,  // only required on Safari
    cache: false,
    type: 'GET',
    url: apiBaseUrl + 'GetStandardTexts?page=login',
    dataType: 'xml',
    success: displayRegisteredAlert,
    error: function(jqXhr, status, error){
    var err = eval("(" + jqXhr.responseText + ")"); 
    alert(err.Message);    
  }  
});

Upvotes: 1

Related Questions