Jump to content

AJAX - settimeout problem?


sayedsohail

Recommended Posts

hi everyone,  this is related to ajax question:  I am trying to reset the xmlhttp in the nested loop:  i.e, if the satus is not 200 than it should abort and try again for couple of times before it gave up, than it should display a message to the user.  rather than just showing alerting the user.

 

var iInterval=1000;
function handleEventsites() {

// check the readystate == 4

if(httpsites.readyState == 4) 
	{
	 // continue only if HTTP status is "OK"
		if(httpsites.status == 200)
		{
			// read the response
			var response = httpsites.responseText;
			// server error?
				if (response.indexOf("ERRNO") >= 0 
				|| response.indexOf("error") >= 0
				|| response.length == 0)
				setTimeout(handleEventSites,iInterval);
				//alert(response.length == 0 ? "Server error." : response);
				// if everything went well, display datagrid
				else 

				document.getElementById("displaysites").innerHTML = response;


		}
		else 
		{    

			// undo any changes in case of error
			setTimeout(handleEventSites,iInterval);
			//alert("Error on server side.");

    
		}
		}
else {
// checking the httpsites readystate and display appropriate message if it fails otherwise just update the div
	document.getElementById('displaysites').innerHTML = "Loading... <img src='http://localhost/images/indicator_white.gif'>";
	setTimeout(handleEventSites,iInterval);

	}					
} 

Link to comment
Share on other sites

The code i managed does throtlling, Is there anyway to avoid server throtlling, and abort the requests if the server is busy.

 

IF someone types quick, this is the error i am getting:

 

Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: http://127.0.0.1/dels.js :: handleEvent :: line 60"  data: no]
Source File: http://127.0.0.1/dels.js
Line: 60

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.