hey, fellas.. I was gonna make a simple website.. Which somehow explains you about the readystate exchange,. But i am not getting the desired ouput. Please help me out.. I am ginna upload the codes, of the javascript and the html file..

the javascript file {a.js}: http://codeviewer.org/view/code:33b6

_______________________________________________________________

the html file: http://codeviewer.org/view/code:33b7

__________________________________
PLEASE HELP ME OUT.. THANKS!

Member Avatar for LastMitch

Which somehow explains you about the readystate exchange,. But i am not getting the desired ouput. Please help me out.. I am ginna upload the codes, of the javascript and the html file..

Try to post your code on the thread not from a link.

Javascript:

var xmlHttp= createxmlhttprequest();

function createxmlhttprequest(){

var xmlHttp;
if(window.XMLHttprequest){

xmlHttp= new XMLHttpRequest();

}
return xmlHttp;

}

function process(){
// wheither ajax worked!
if(xmlHttp){
try{

xmlHttp.open('GET', 'welcome.txt', true); //cofigrues the connection settings!

xmlHttp.onreadystatechange = handleTheServerResponse; //anytime something changes call handleTheServerResponse;

xmlHttp.send(null); //connects the server!

}catch(e){
alert(e.toString());

}
}
}

function handleTheServerResponse(){

again=document.getElementById("again");

if(xmlHttp.readyState==1){
again.innerHTML+= "status1 server connection extablished<br>";

}else if(xmlHttp.readyState==2){

again.innerHTML+='status 2: reuqesu is recieved<br>';
}
else if(xmlHttp.readyState==3){

again.innerHTML+='status 3: Processing your request<br>';
}

else if(xmlHttp.readyState==4){
// 200 means a successful communication!
if(xmlHttp.status==200){
try{
text=xmlHttp.responseText;

again.innerHTML+='status 4: You request has been successfully completed!<br>';

again.innerHTML+=text;
}catch(e){
alert(e.toString());
}

}else{
alert("FATAL ERROR: cannot reach readystate 4");
alert(xmlHttp.statusText);
}
}
}

HTML:

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='a.js'></script>
</head>
<body onload="process()"/>
Ok you made this far!
</br>

<div id='again'/>
</body>
</html>

What are you trying to ajax? It looks fine (meaning I don't see anything out of an original). Which browsers does it have trouble?

Take a look at these 2 links which has a code snippet you can add it to your own code:

http://coursesweb.net/ajax/xmlhttprequest-object

http://www.cristiandarie.ro/asp-ajax/Async.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.