views:

176

answers:

4

Hi

I am not really sure what to do in this situation. I have some jquery ui 1.7 tabs that are ajax enabled. Now when a tab is clicked it goes to my asp.net mvc controller action method. That then does whatever is needed and return a partial view.

Now I don't know why but sometimes my server hangs but then again I am guessing all servers hang since sometimes when I go to sites it take forever to load but if you do a refresh it loads up instantly and that's the same case with my site.

My site will load up a tab super fast for X number of times then all of a sudden a request will just hang and maybe like 15seconds later it will load up. Or if you just refresh the page it will go back and start loading them up super fast again.

The problem though is the request is sent to the server where it hangs. So I tried to setup a jquery timeout on all my ajax stuff and that calls an abort to the jquery ui tabs.

But it never works and I guess from what I gathered reading on this site is because the request is on the server and abort won't stop stuff on the server. So if I look at firebug that request that hanged is stil running.

Now this causes a huge problem for me since it screws up the entire page what is heavily ajax. Like if the user tries to click on say another tab they will most likely have to click 2 times to get it to load up. Another thing what happens is if that request ever finish hanging whatever tab they are on will merge with that tab. So sometimes one tab will have parts from all the other tabs.

So if it hangs and does not finish it really messes with the ajax tabs. I have no clue how to fix this.

So I am not sure what to do.

Let them hang for however long it takes the server to figure out how to finish that request(when a ajax request is made I disable all tabs. This is because if a person say loaded up a tab and did not let it finish and tried to go to another tab the same problem would occur with the tabs merging together). Or abort the request and have a screwed up tabs.

Great choices I got. Anyone got any better choices?

Thanks

A: 

We've had good success using jquery queue manager - http://www.protofunc.com/scripts/jquery/ajaxManager/

When a second request is performed it aborts the first request. I'm not sure about a timeout, but there are several options you can play with.

Arthur Frankel
So do I have to rewrite my ajax stuff? How could I put this on jquery ui tabs. You just set it up as a link and does it internally i believe.
chobo2
It's just a few lines of code to add (not rewrite) - but only if you have access to the ajax code currently.
Arthur Frankel
Well I don't wnat to change the jquery ui code. Since if i ever upgrade then it will be overriden.
chobo2
So how where do I add these few lines? Like I am using "post" and "get" most of the time.
chobo2
Once you create the queue you just add to it...e.g. myQueue.add({ url: "/whateverurl", type: "POST", data: { myVar : myData, ... }, abort: function(){ abortMe(); }, success: function(data) { ... }, error: function(data) { handleErrors(data); } });
Arthur Frankel
Sorry, I couldn't format the code properly in my last response.
Arthur Frankel
+1  A: 

I'm not sure what you mean by "jquery timeout". if you mean setTimeout, that definately won't work. If you mean, on the other hand,

$.ajax({
     url:"myserverprocess", 
     timeout: 200, 
     error: function () { /* try again */ }, 
     success: function (myadata) { alert("mydata")}
});

then that should work. Try the timeout option if you haven't yet.

edit: you could try :

$(selector).tabs({
    ajaxOptions: {
        url:"myserverprocess", 
        timeout: 200, 
        error: function () { /* try again */ }, 
        success: function (myadata) { alert("mydata")}
    }
});
Breton
Thats what I use. I have $.ajaxSetup( { 'timeout': 15000, 'error': errorCallback });I think this has the power to kill all the ones except the jquery ui tab requests.
chobo2
I tried to do it in the tabs one too. But according to the documentation the one in ajaxSetup will override it anyways.
chobo2
You could have a typo or other related mistake in your code. if you post some of it maybe we can diagnose. One thing to do is to make a really stripped down minimal page that demonstrates the bug and put it on jsbin for us to look at and play with.
Breton
A: 

You could use Jquery to set a timeout on your ajax call and then catch it in the error section. Once caught, you could deal with retrying or doing any needed cleanup.

Mercurybullet
I use the jquery timeout. NOt sure how to do cleanup on it though.
chobo2
+1  A: 

We have a similar situation here in that the 1st person to hit the site for the day will incure a 15 second delay while things are loaded.

In our situation, on all calls to the server via jQuery, I have set a normal javascript timeout for 2 seconds. After 2 seconds I pop up a small div saying something like things are talking longer than expected and please be patient.

after a further 6 seconds i close that div and open a new one with more of an apology.

not a great solution but it does keep the user in the loop, comfortable that things are ticking along and that we acknowledge things are not perfect.

warm and fuzzies as we call them here. :)

griegs
Ya that is not too bad. It is not a fix but better then nothing I guess. I if no one can give me something better I will move to this solution.
chobo2
Like you say it's not a fix but sometimes you are aware of lags and you are aware there is nothing you can do about them. but letting the customer just sit there waiting is the quickest way to losing them. at least if you provide feedback you can postpone their departure and hopefuly retain them till the system comes back. obviously there are other ways to deal with complete hangs and this isn't one of them.
griegs