Learn jquery from scratch (vi) AJAX fast Food

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.