We help IT Professionals succeed at work.

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

infernothao
infernothao asked
on
2,813 Views
Last Modified: 2013-12-08
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

Comment
Watch Question

CERTIFIED EXPERT

Commented:
did you tried removing lines 36-44 and check?
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.

Author

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

Author

Commented:
@apresence, fixed that typo but still error.
CERTIFIED EXPERT

Commented:
<<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...";
            }

Author

Commented:
Well, the thing is it will take anywhere between 5-30 minutes. It would be nice to know how long it will take.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the advises.

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.