views:

28

answers:

1

Hello, I've noticed this weird behaviour of jQuery in Safari. After setting up the call like this:

$.ajax( {
    'url' : url,
    'dataType' : 'json',
    data : reqdata,
    timeout: 20000, //10 secs of timeout 
    success : function(data, textStatus, XMLHttpRequest) {
        console.log("success");
        if ((data === null) || (data.length == 0)) {
            ts.doAction( {
                'actionName' : 'timeout',
                'request' : {
                    'reqdata' : reqdata,
                    'actionName' : actionName,
                    'url' : url
                },
                'controller' : ts
            });
        }

        ts.doAction( {
            'actionName' : actionName,
            'data' : data
        });
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
        console.log("error: " + textStatus);

        if (textStatus == "timeout") {
            ts.doAction( {
                'actionName' : 'networkFailureError',
                'request' : {
                    'reqdata' : reqdata,
                    'actionName' : actionName,
                    'url' : url
                },
                'controller' : ts
            });
        } else {
            ts.doAction( {
                'actionName' : 'serverError',
                'request' : {
                    'reqdata' : reqdata,
                    'actionName' : actionName,
                    'url' : url
                },
                'controller' : ts
            });
        }
    }
});

If a timeout occurs (I switch the local webserver off), the 'success' method will be called! More than this in the textStatus parameter there is a string with "success" !!! The error handler doesn't even get called.... (As you may notice the only way I had to tell the problem, was to check the data param if it is null or 0 length... Why this behaviour? How can I avoid this?

A: 

Sounds like your request is being cached.

Try the $.ajax call with the cache: false option set. Per the API docs:

If set to false it will force the pages that you request to not be cached by the browser.

You may also want to verify that your request's response is being cached by viewing the request/response using Firebug, Fiddler or some other web request monitoring tool.

David Hoerster
No way. Even before I was not getting the timeout working... The success handler was called and data body was null. Is this behaviour related to safari???
gotch4