Avatar of infernothao
infernothao
 asked on

IE - Ajax problem - Data necessary to complete this operation is not yet available

Hi Experts, I'm trying to make a call to ajax which it supposes to return the percentage left while waiting for the file to finish generating info. Everything works fine in Firefox but in IE it generates an error as stated in the topic. It does work in IE but with an error. Below is the javascript I used. If I were to comment out the line after  "ajaxRequest.readyState == 3" (line #37)  it seems to work without any error.
/*---------------------------------------------------------

----------------------------------------------------------*/
function generateCompleteExport(data){
	ajaxRequest = GetXmlHttpObject(); 
	ajaxRequest.async = false;
	if (ajaxRequest==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var loadingImg = '<img src="/reports/assets/scripts/loading.gif" title="Loading...">';
	document.getElementById('status').innerHTML = loadingImg;
	
	// Add parameter 'q' to URL
	var url = 'completeExportGenerate.php?'+data;	
	// Adds a random number to prevent the server from using a cached file
	url=url+"&sid="+Math.random();	
	
	var numTest =0;
	var response;
	var index;
	
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.status == 200) {
				response = ajaxRequest.responseText.split("###");
				index = response.length-1;
			
				document.getElementById('status').innerHTML =response[index];
			} else {
				//window.status = "No Update for " + targetId;
				document.getElementById('status').innerHTML="Error code " + ajaxRequest.status;
			}
		}
		if(ajaxRequest.readyState == 3){
			response = ajaxRequest.responseText;.split("###");
			if( (response.length-2)<= 0)
				index = 0;
			else
				index = response.length -2;
				
			document.getElementById('status').innerHTML =loadingImg+'<br>'+response[index];
		}
	}
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null);
}

Open in new window

Web BrowsersJavaScriptAJAX

Avatar of undefined
Last Comment
infernothao

8/22/2022 - Mon
Gurvinder Pal Singh

did you tried removing lines 36-44 and check?
apresence

There is a typo on line 37:
response = ajaxRequest.responseText;.split("###");

It should be:
response = ajaxRequest.responseText.split("###");

About the ready states, you can find more info here:
http://www.devx.com/webdev/Article/33024/0/page/2

State 3 means the page is still loading, so the data is not going to be ready for you yet.
infernothao

ASKER
Thanks for answering guys. I'm pretty new to ajax...  anyway, I'm not totally sure what readyState == 3  do but I read some where it says something about interacting between the client and the server. The reason I need line 36-44 is because I want to update the progress bar percent while the file is being generated in the background. Hmm... when I changed the "responseText" to "responseXml" it seems to stop the error. I have tried using responseXml before but I have no clue how to send data back using Php.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
infernothao

ASKER
@apresence, fixed that typo but still error.
Gurvinder Pal Singh

<<I'm not totally sure what readyState == 3  do but I read some where it says something about interacting between the client and the server>>
Not required to handle in most cases.
You can read about it here
http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp

In case you want to indicate the user that response is being processed at the background, then you can update those lines to

if(ajaxRequest.readyState == 3){
                  document.getElementById('status').innerHTML ="Response is fetched, loading...";
            }
infernothao

ASKER
Well, the thing is it will take anywhere between 5-30 minutes. It would be nice to know how long it will take.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
apresence

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
infernothao

ASKER
Thanks for the advises.
infernothao

ASKER
Guess I'm so focus on one think that I couldn't think straight. Thanks for Apresence for not giving up on me and give me something to work on. The solution I came up with is  somewhat a combination of what Apresence's advises. Every 5 seconds or so I'll load and read a XML file generated by PHP. Thanks.