Learn More... SQLsnap Logo. SQLsnap Screenshot. Buy Now or Learn More!

Extend Ext JS Ajax Timeout

February 18th, 2010

The default timeout for Ext ajax requests is 30 seconds.   Sometimes that is plenty but other times it’s not nearly enough. 

To extend the timeout duration for  Ext.Ajax.request({…..}); you must add the following statement:

  Ext.Ajax.timeout = 90000; // this changes the 30 second default to 90 seconds

Since Ext.Ajax is a singleton, this only needs to be done once at the top of the js file that you want to extend the timeout for.

So once the above line executes, the Ext.Ajax.requests will allow for a 90 second timeout.  The value is in milliseconds so just add 3 zeros to whatever timeout you want the timeout duration to be:

90000 (90 seconds)

180000 (3 minutes)

Ext.onReady(function(){

                // Extend timeout for all Ext.Ajax.requests to 90 seconds.
                // Ext.Ajax is a singleton, this statement will extend the timeout
                // for all subsequent Ext.Ajax calls.
                Ext.Ajax.timeout = 90000;

                Ext.MessageBox.show({
                    title: "Executing Ajax Call",
                    msg: "Timeout has been extended",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.INFO
                });

                // Make ajax call.  Timeout is now set to 90 seconds.
                Ext.Ajax.request({
                    url: '/myurl.do',
                    params:{
                        action: "getInfo",
                        cust: "555"
                    },
                    success: function(response) {

                        var returnValue = response.responseText;

                        Ext.MessageBox.show({
                            title: "Customer Info",
                            msg: "Here is your customer info " + returnValue,
                            buttons: Ext.MessageBox.OK,
                            icon: Ext.MessageBox.INFO
                        });

                    },
                    failure: function(response) {
                        Ext.MessageBox.show({
                            title: "Ajax Call Failed",
                            msg: "Your timeout was extended but the call still failed.",
                            buttons: Ext.MessageBox.OK,
                            icon: Ext.MessageBox.ERROR
                        });

                    }
                });
            });

Ext.Ajax API

Scott


Posted in: Extjs 3.
Subscribe: RSS 2.0 feed.

  • Of course you also need to extend the time in the server side :)

    PHP
    set_time_limit(20);

    .NET
    <httpruntime executiontimeout=""> or Server.ScriptTimeout value in the Page Load.</httpruntime>

blog comments powered by Disqus
  • « Older Entries