my javascript hangs the browser (make it unresponsive)

Posted on 2006-10-19
Last Modified: 2007-12-19
Hello All,
    The java script i am working on makes the browser unresponsive. The browser becomes responsive after the javascript function finishes.

The script is huge and is used to communicate with server using SOAP messages (called through 3rd party API).

How can i resolve this?

Thanks in Advance.
Question by:manish_regmi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

VovinE earned 500 total points
ID: 17763829
I this may be because of the loop in javascript.
If there is a loop waiting for response to arrive, then it may hang your browser.

You should get rid of the loop and set a callback function (onreadystatechange) for your XMLHttpRequest object, to handle data coming back asynchronously.

Author Comment

ID: 17764098
ok. i see. thanks.

so. i need to change my code to make it asynchronous.

But i have one such request in loop how can i make it asynchronous.


function tmp()
                  tmp = getParentName(idarr[idx-1]);
                  if(tmp === false)

                  idarr[idx] = tmp;
            //      alert(idarr);

getParentName does some SOAP request. I can add an extra parameter for a callback routine but how to implement loop logic.


Expert Comment

ID: 17764184
well, you would need to make getParentName function asynchronous.
It seems, it waits until the soap request is finished - and inside this function loop causes browser to hang.

SOAP requests should be simple enough not to make several calls to request for data.
You might try to refactor your code, so only one SOAP call is required - which would return an array you need, not to make call for each item.

Expert Comment

ID: 17764234
If you still need to implement loop asynchronously without refactoring the webservice, then:

implement a function, that starts precalculation (in pseudocode):

var idarr= new Array();
var idx;
function PerformCalculation()
  // todo: initialize your array
   StartRequest(myCallback); //you need to make sure everything is set up (SOAP Header and so on)
  // it should set asynchronous callback on result to myCallback
function myCallback(result)
         if(result == false){
        } else {
           idarr[idx] = tmp;

function CalculationFinished(arr)
   // do whatever you need with the result :)

StartCallback should return immedietaly after setting asynchronous callback.


Author Comment

ID: 17764274
thanks VovinE for your help.

Manish Regmi

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Datatables.js Selecting a Row to get ID 5 36
Sending ASP to server side 8 31
Link not working 6 42
How do I add counter to html listbox using jquery 2 26
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question