Wednesday, February 4, 2009

ajax for beginners

I dont know why some one has named it ajax. but in 2003 i have written an application using xmlhttp object . which was used to communicate with xml webservice to get a resultset. and display the results in excel.

i will show the example what i have done in my next post.

motivation is share mere yaar " share the knowledge" .

ajax is asynchronous call made using javascript either to the .net web application or webservice.

we need following minumum javascript methods to make a call.

/*---- Get xml http object ---*/

function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;


function stateChanged() {
if (xmlHttp.readyState == 4) {
....Write your code to assign response to the html dom element.

here is the java script funtino can be called on each key up on text box
following function gets the employee details from getEmployee.aspx page.

function showEmployee(str) {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("Your browser does not support AJAX!");
var url = "getEmployee.aspx";
url = url + "?q=" + str;
url = url + "&sid=" + Math.random();
xmlHttp.onreadystatechange = stateChanged;"GET", url, true);

any questions please drop a question.


No comments:

Post a Comment