Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Friday, August 10, 2007

Few tips while using Ajax

While using Ajax in your application , dont assign

xmlHttpObject.onreadystatechange=null.

Because some browsers does not allow it.They neither show a warning nor an error. Especially IE does not support this case.

Instead replace that with
xmlHttpObject.onreadystatechange = function(){};

Similarly while using "POST" method in ajax, you need to specify some header
informations like Content-type,Content-length and Connection.

for example,

var postdata="your data that is to be submitted"
var url="http://www.test.com/servlet/testservlet";
xmlHttpObject.open("POST",url,true);
xmlHttpObject.onreadystatechange = function(){};
xmlHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpObject.setRequestHeader("Content-length", postdata.length);
xmlHttpObject.setRequestHeader("Connection", "close");
xmlHttpObject.send(postdata);