Whats wrong with this code?

H

hiqu

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(;;)
{
}
}
 
H

hiqu

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.
 
E

Erwin Moller

hiqu schreef:
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
 
Á

Álvaro G. Vicario

hiqu escribió:
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?

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

Well, this is pretty obvious xD
 
G

GArlington

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.
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...
 
G

GArlington

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top