For XML Response:
- Set the content type to "text/xml". Eg.
response.setContentType("text/xml");
- Before creating the XML content always clear the buffer. Calling clearBuffer() of JspWriter is better than calling just clear() method as the earlier won't throw any exception. Eg.
out.clearBuffer();
While creating the XML content there has to be a root element. Eg.
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<list>
<student>
<id>990</id>
<name>Sujoy C</name>
</student>
<student>
<id>991</id>
<name>Tanmoy C</name>
</student>
</list>
To Post Data:
- Set the content type of request header to "application/x-www-form-urlencoded"
- Create the post parameters and set the content length. eg. xmlReqObj.setRequestHeader("Content-length", params.length);
- Code example:
try
{
xmlReqObj.open("POST", URL, true);
xmlReqObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlReqObj.setRequestHeader("Content-length", params.length);
xmlReqObj.setRequestHeader("Connection", "close");
xmlReqObj.send(params);
} catch(err)
{}
I shall try the following things and keep posted:
- How can I pass argument to the function onreadystatechange?
- The status attribute most of the time throws error. Why does this happen and how to resolve this?