I. Summary
This series of articles will take you into the wonderful world of jquery, with many authors ' specific experiences and solutions, even if you can use jquery to find some cheats in your reading.
This article explains how to use jquery to quickly and easily implement AJAX functionality. Unify the way that all developers use Ajax.
Two. Foreword
Ajax makes the user page richer and enhances the user experience. Using AJAX is a required course for all web development. Although Ajax technology is not complex, the implementation is still different for each developer. jquery provides a series of Ajax functions to help us unify the differences and make it easier to invoke Ajax.
Three. Ajax in raw Ajax and jquery
First, take a look at how simple jquery is to implement Ajax. Here is an example of using raw AJAX:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>jquery ajax</title>
<script type= "Text/javascript" >
$ (function ()
{
var xhr = new Ajaxxmlhttprequest ();
$ ("#btnAjaxOld"). Click (Function (Event)
{
var xhr = new Ajaxxmlhttprequest ();
Xhr.onreadystatechange = function ()
{
if (xhr.readystate = 4)
{
document.getElementById ("Divresult"). InnerHTML = Xhr.responsetext;
}
}
Xhr.open ("Get", "data/ajaxgetcityinfo.aspx?resulttype=html", true);
Xhr.send (NULL);
});
})
Get XMLHttpRequest objects across browsers
function Ajaxxmlhttprequest ()
{
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;
}
}
}
return xmlHttp;
}
</script>
<body>
<button id= "Btnajaxold" > Original ajax call </button><br/>
<br/>
<div id= "Divresult" ></div>
</body>