Delay in getting the response in xmlhhtp Request

  • Thread starter balakrishnan.dinesh
  • Start date
B

balakrishnan.dinesh

hi friends,
Im having a xmlhttp request function , i have put that
xmlhttp function in seperate .js file, becoz i want to reuse the
function more pages,

Code is below:
this is script 1:
<script>
var xmlhttp;
var CrossDomainPage;
var srecords1;
function xmlhttpRequest(url) /* Used to get the Response
through XmlHttp */
{
if (window.XMLHttpRequest)
{

xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null)
}

/* code for IE */
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
alert(url);

xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send()
}
}
}
function state_Change()
{
/* if xmlhttp shows "loaded" */
if (xmlhttp.readyState==4)
{
/* if "OK" */
if (xmlhttp.status==200)
{
CrossDomainPage = xmlhttp.responseText;

if (CrossDomainPage == " ")
{
alert("Server is Down!!Please Wait");
return null;
}
alert("c "+CrossDomainPage); => alert must
srecords1=CrossDomainPage;
alert("srec"+srecords1); => alert must
}
else
{
alert(xmlhttp.status+"Problem retrieving
data:")
}
}
}
</scrip>

script 2: from this script only im calling the xmlhttp request function
<script>
var resp=xmlhttpRequest(url);
alert(resp); => alert must
document.write(resp)
</script>

The problem with code is,
I have specified some alerts are "alert must". the response is
printed only those alerts
are present in the code, if i take it off means ,its not displaying
anything.
And when displaying the data in tha page with those alerts, the
alert(resp) is showing null.

plz give me a suggestion, that what to be change in the code

thank u
Dinesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top