HighDots Forums  

Whats wrong with this code?

Javascript JavaScript language (comp.lang.javascript)


Discuss Whats wrong with this code? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hiqu
 
Posts: n/a

Default Whats wrong with this code? - 06-12-2008 , 11:54 AM






This issue is driving me nuts and not able to figure out whats wrong.
I've this code in my firefox extension. Firefox always hangs and
reports the script is busy.

if I introduce a break statement in the for(; loop below, then
no issue.

Any help would be appreciated!

function getStuff()
{
try
{
httpReq = new XMLHttpRequest();


httpReq.onreadystatechange = function(evt)
{
if (httpReq.readyState == 4)
{
if (httpReq.status == 200)
{
getList(httpReq.responseText);
}
}
}


httpReq.open("GET", "http://www.mysite.com", true);
httpReq.send(null);
}catch(ex)
{
Components.utils.reportError(ex);
}
}


function getList(htmlText)
{
for(;
{
}
}

Reply With Quote
  #2  
Old   
hiqu
 
Posts: n/a

Default Re: Whats wrong with this code? - 06-12-2008 , 12:10 PM






On Jun 12, 9:54*am, hiqu <hiqul... (AT) gmail (DOT) com> wrote:
Quote:
This issue is driving me nuts and not able to figure out whats wrong.
I've this code in my firefox extension. Firefox always hangs and
reports the script is busy.

if I introduce a break statement in the for(; loop below, then
no issue.

Any help would be appreciated!

function getStuff()
{
* * try
* * {
* * * * httpReq = new XMLHttpRequest();

* * * * httpReq.onreadystatechange = function(evt)
* * * * {
* * * * * * if (httpReq.readyState == 4)
* * * * * * {
* * * * * * * * if (httpReq.status == 200)
* * * * * * * * {
* * * * * * * * * * getList(httpReq.responseText);
* * * * * * * * }
* * * * * * }
* * * * }

* * * * httpReq.open("GET", "http://www.mysite.com", true);
* * * * httpReq.send(null);
* * }catch(ex)
* * {
* * * * Components.utils.reportError(ex);
* * }

}

function getList(htmlText)
{
* * for(;
* * {
* * }



}- Hide quoted text -

- Show quoted text -
actually, let me post the correct code. I do some stuff in the for
loop.


Reply With Quote
  #3  
Old   
Erwin Moller
 
Posts: n/a

Default Re: Whats wrong with this code? - 06-13-2008 , 04:20 AM



hiqu schreef:
Quote:
On Jun 12, 9:54 am, hiqu <hiqul... (AT) gmail (DOT) com> wrote:
This issue is driving me nuts and not able to figure out whats wrong.
I've this code in my firefox extension. Firefox always hangs and
reports the script is busy.

if I introduce a break statement in the for(; loop below, then
no issue.

Any help would be appreciated!

function getStuff()
{
try
{
httpReq = new XMLHttpRequest();

httpReq.onreadystatechange = function(evt)
{
if (httpReq.readyState == 4)
{
if (httpReq.status == 200)
{
getList(httpReq.responseText);
}
}
}

httpReq.open("GET", "http://www.mysite.com", true);
httpReq.send(null);
}catch(ex)
{
Components.utils.reportError(ex);
}

}

function getList(htmlText)
{
for(;
{
}



}- Hide quoted text -

- Show quoted text -

actually, let me post the correct code. I do some stuff in the for
loop.
What is your question?
I am afraid I cannot follow your line of thought at all. :-/

Regards,
Erwin Moller


Reply With Quote
  #4  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Whats wrong with this code? - 06-13-2008 , 05:32 AM



hiqu escribió:
Quote:
function getStuff()
{
try
{
httpReq = new XMLHttpRequest();
Since httpReq is global, every time you getStuff() you'll destroy any
other AJAX call that may be executing. Is that the desired effect?


Quote:
function getList(htmlText)
{
for(;
{
}
}
Well, this is pretty obvious xD



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--


Reply With Quote
  #5  
Old   
GArlington
 
Posts: n/a

Default Re: Whats wrong with this code? - 06-13-2008 , 06:27 AM



On Jun 12, 5:54 pm, hiqu <hiqul... (AT) gmail (DOT) com> wrote:
Quote:
This issue is driving me nuts and not able to figure out whats wrong.
I've this code in my firefox extension. Firefox always hangs and
reports the script is busy.

if I introduce a break statement in the for(; loop below, then
no issue.
snap

function getList(htmlText)
{
for(;
{
}

}
The above is never ending loop, this is an equivalent of telling your
CPU to do nothing (NOP) but be BUSY all the time...


Reply With Quote
  #6  
Old   
GArlington
 
Posts: n/a

Default Re: Whats wrong with this code? - 06-13-2008 , 06:29 AM



On Jun 12, 6:10 pm, hiqu <hiqul... (AT) gmail (DOT) com> wrote:
Quote:
On Jun 12, 9:54 am, hiqu <hiqul... (AT) gmail (DOT) com> wrote:

snap

actually, let me post the correct code. I do some stuff in the for
loop.
Please do (post the correct code), because the posted code does
EXACTLY what you can expect it to do - hangs you machine...


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.