Three ways to simplify Ajax techniques in jquery

Source: Internet
Author: User
Tags html page json

JQuery offers load,$.get,$.post three ways to make Ajax easier to write, and it's a complex task that is no longer complicated.

The Load method is the simplest and most commonly used Ajax method in jquery to load remote HTML code into the DOM, which is structured
Load (Url[,data][,callback])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
Example: Loading a test.html file
$ (' #stats '). Load (' test.html ');
Both the $.post and $.get methods pass some parameters to a page processing in the server.
The $.post method is to use post to submit data, which is structured as
$.post (Url[,data][,callback][,type])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
The format returned by the type server includes XML, HTML, script, JSON, text, and _default
For example:
$.post (' test.php ', {
Text: ' My string ',
Number:23
}, function () {
Alert (' Your data has been saved. ');
});
The $.get method is to use get to submit the data, which is structured as
$.get (Url[,data][,callback][,type])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
The format returned by the type server includes XML, HTML, script, JSON, text, and _default
$.get (' test.php ', {
Text: ' My string ',
Number:23
}, function () {
Alert (' Your data has been saved. ');
});

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.