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);}
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.
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.