问题描述:

I am doing some stuff with ajax-Requests within PhantomJS. Unfortunately there is a 30s timeout for ajax-Requests within a PhantomJS-webpage.

I've been trying to set the timeoutproperty in the $.ajax-settings. Unfortunately this seems to get ignored completely. Same goes for:

$.ajaxSetup({

timeout: 120000

});

Then there is the ExtJS framework extension. Unfortunately Extis undefined within the PhantomJS WebPage. So this does not work aswell.

Any suggestions?

网友答案:

Since $.ajaxSetup sets the default values, it cannot be used to override existing "setups" or ajax requests that set timeout. It seems, you can override with $.ajaxPrefilter.

According to the comments, this has to be done before the page load. I assume the first ajax request is not yet sent when DOMContentLoaded is triggered.

page.onLoadStarted = function(){
    page.evaluate(function(){
        document.addEventListener('DOMContentLoaded', function(){
            $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
                options.timeout = 120000;
            });
        }, true);
    });
};
相关阅读:
Top