PDA

View Full Version : Store.load callback triggering before load finishes



clockwork
14 Aug 2008, 12:19 PM
Hi everyone, I'm pretty new to Ext (I first saw it 3 days ago) and I'm working on some code that somebody else wrote. I'm running into a problem where the Ext.data.Store.load method is firing off the 'load' event before the load is actually complete. It has the same behavior when I provide load() with a callback function, as in the code I've included. What I'm trying to do is get back search results from a server and display them in the app. This happens only on the first search after I start the server and when I repeat the search load comes back just fine.

Here's the section of code that has the problem:


SearchResultsPanel.searchResultsStore.load({params:{start:0,limit:25},
callback: function(r,options,success) {
if(success == true) {
if(r.length == 0) {
SearchResultsPanel.clear();
}
else {
SearchResultsPanel.addGridIfNeccessary();
}
}
else {
alert("failed");
}
}});
success is coming back false on the first search after the server is started, but the load seems to continue anyway because the data does come back correctly, but not until after the callback function has finished. All the searches after the first one come back and behave correctly.

Thanks in advance

Animal
14 Aug 2008, 12:28 PM
The load event is fired just before the callback is called if that's what you mean.

Not sure I understand the problem though.

clockwork
14 Aug 2008, 1:11 PM
The problem is that the callback is being called before the load is complete and the success boolean is false. I'm running the java and js for the app in jetty. The "failed" alert that is in the callback function pops up and after that some of my debug code prints the data that was loaded from the store to the jetty window. So load is telling me that it failed and calling the callback, but then proceeds to complete successfully, but the callback doesn't get the loaded data.

devnull
14 Aug 2008, 2:20 PM
That sounds to me like there may be two requests being made back to back, the first of which fails and the second succeeds. Maybe a redirect or something? Do you have a way to see actual http transactions with your setup to see whats going on at a low level? (I dont know anything about jetty so do not know if firebug is involved).

clockwork
14 Aug 2008, 2:40 PM
I am using firebug. Under the conditions that fail the server takes much longer to respond since nothing is cached yet. On subsequent runs the data is cached and comes back much quicker. When it's failing, firebug doesn't show any http request transaction under the Net tab, but shows the request on the console tab. When it succeeds this is what the Net tab gives me
Params:


_dc 1218753025672
then some of my params
Headers:


Response Headers
DateThu, 14 Aug 2008 22:30:25 GMTCache-Controlno-cacheContent-Typetext/xmlTransfer-EncodingchunkedServerJetty(6.1.8)

Request Headers
Hostlocalhost:8080User-AgentMozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1Accepttext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Languageen-us,en;q=0.5Accept-Encodinggzip,deflateAccept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive300Connectionkeep-aliveX-Requested-WithXMLHttpRequestRefererhttp://localhost:8080/mice/The response has my expected response in it, but it's long and meaningless to post here.

Animal
14 Aug 2008, 11:06 PM
We need to see more code.

And your JSON.

If the success is being returned false, then there's been a problem converting the JSON into Records.

clockwork
15 Aug 2008, 12:15 PM
I found the problem. The timeout on the connection provided to the HttpProxy was at the default value of 30 seconds, which is just fine after the data has been cached by my server, but is short of the amount of time it takes to look things up for the first time. So it was timing out and calling the callback function with a failure. The solution was to up the timeout value when I set up the HttpProxy like so:


proxy: new Ext.data.HttpProxy({
url: "invoke",
method: "GET",
headers: {},
timeout: 60000
}),


Thank you, Animal and devnull for taking the time to read this and help me.