Ajax by Mukesh Singh, 19th dec, 2007 Primary characteristic of ajax is the increased responsiveness and interactiveness of web pages achieved by exchanging small amounts of data with the server "behind the scenes"Data is retrieved using the XMLHttpRequest object that is available to scripting languages run in browsers XMLHttpRequest is important. function ajaxFunction() {var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } }
Explaination var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) this snippet creates object of xmlhttprequest for firefox opera safari browser catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) this snippet creates object for IE try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) this one also use to create same object for IE i mean to say now u have xmlhttprequest object to send req to database next task is to send this request to database but question is how? xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); in this statement new ActiveXObject("Microsoft.XMLHTTP") is used to create a instace of xmlhttprequest onreadystatechange Property this is really important property After a request to the server, we need a function that can receive the data that is returned by the server The onreadystatechange property stores the function that will process the response from a server. syntax is xmlHttp.onreadystatechange=function() { // We are going to write some code here } The readyState Property The readyState property holds the status of the server's response About the Author: Mukesh Singh is currently working with arion technology as Senior Engineer and having responsibilities responsbilities of team lead and technical architect. He has a vast experience of more than 3 years in Java/j2ee, spring, web services including Ajax. For any mistakes or wrong information interview fundas will not be responsible. All rights reserved by Mukesh Singh. He can be reached at
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
|