|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Ok guys, need a bit of help, i hate to admit that but im tearing my hair out
Ok firstly, do not shout when i tell you this but i have been running ajax synchronously in my functions for my firefox addon, simply because i have to grab 10 posted iterations of a page, each may have a different result (good/bad/fail) and i need to tally them up and display the user with a final result. old way was setting the async value in the xmlhttprequest to false, i still need to do this from what i understand of it, but i believe i can do so without freezing the users browser by using threads (ooooh threads you say) ok heres how that would work: Code:
backgroundTask = {
run: function() {
// I am putting my synchronous ajax code in here
}
}
var thread = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager )
.newThread(0);
thread.dispatch(backgroundTask, thread.DISPATCH_NORMAL);
which is from the mozilla site, but not working for me. Then i read that you can run stuff in the background by using something like : Code:
var thread = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager )
.currentThread;
while (!complete)
thread.processNextEvent(true);
my question is this, does anyone know how i can run 10 synchronous ajax calls in the background without freezing the users browser? (they know it will happen and accept it, but they should NOT be putting up with my crappy coding stopping them for the duration of the ajax calls). i believe my solution is in threads, anyone want to help?
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car. |
|
#2
|
||||
|
||||
|
ok how about forget the whole firefox addon bit, and maybe a bit of help with javascript and threading?
so I need a way to run xmlhttprequest with async flag set to false (as i need to read the response before proceeding) while not freezing the users browser? something similar can be seen here: http://sitepointstatic.com/examples...ading/test.html (just need to remove the "counter" and set that with the ajax call) |
|
#3
|
||||
|
||||
|
Never mind, found a way to do it, this thread can be closed.
|
|
#4
|
|||
|
|||
|
I would personally just return one JSON object with all posted pages and return that. Even if you had to use php to get the results and act as a proxy (ie ajax contacts a php script on your site and that script gets the 10 posted pages and sends an object back with all 10 responses).
And that test you put a link to did slow down my browser and this is not a slow computer. When I clicked on the X to close the tab, it took a few seconds before it would close and before that the buttons seemed non-responsive. |
|
#5
|
||||
|
||||
|
im just going to use web workers, create one, that creates and monitors multiple subworkers, then returns the value and appropriate responses when its complete, absolutely no interference to the user since as far as he knows its happily working giving him an update on the screen as it proceeds, simply implemented, new feature and, the most important part, does not disturb browsing.
oh and that link i provided simply messed with timing, and delegation so its not true multithreading so, although it did slow your computer down, it did not freeze it like my current way does. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Firefox addon, JS and Ajax - help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|