| Newsletter |
Ajax Server Response, responseText and responseXML
Ajax » on Aug 26, 2011 { 5 Comments } By Sivateja
Once we send the request to the destination [ server ], we will get the response from the server in two formats either in Text or XML, i mean we can get the response from the server by using responseText and responseXML propertys of our XMLHttpRequest object
Actually..
responseText — for getting the response in the format of text
responseXML — for getting the response in the format of XML
You can see this in the first example
Or check this
<html>
<head>
<script type="text/javascript">
function fun1()
{
var a;
if (window.XMLHttpRequest)
{// If the browser if IE7+[or]Firefox[or]Chrome[or]Opera[or]Safari
a=new XMLHttpRequest();
}
else
{//If browser is IE6, IE5
a=new ActiveXObject("Microsoft.XMLHTTP");
}
a.onreadystatechange=function()
{
if (a.readyState==4 && a.status==200)
{
document.getElementById("myDiv").innerHTML=a.responseText;
}
}
a.open("POST","my.txt",true);
a.send();
} // fun1() close
</script>
</head>
<body>
<div id="myDiv" style="width: 300px; height: 30px;">
Click on the button below
</div>
<button type="button" onclick="fun1()">Change Content</button>
</body>
</html>Explanation
- see we are getting the response in the form of text [ see line number 21 ]
- once the response is ready, our div content will be replaced with the response text [ see line number 32 ]
Will see more while discussing Ajax with Servlets
You Might Also Like
::. About the Author .:: | ||
![]() | ||
Comments
5 Responses to “Ajax Server Response, responseText and responseXML”

Really fantastic visual appeal on this website , I’d value it 10 10.
sir at first line of explation is two “are”.u can correct it.and love ur site very much.
@Asif – I did the correction, thank you 🙂
can we put a pdf into the same jsp file using the ajax like here you have done for text file….
VEARY UESFULL THANKSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS