jquery1.4 Tutorial Two improvements to Ajax methods _jquery

Source: Internet
Author: User
Tags html header serialization browser cache
1 allows for serialization of nested parameters.
For example: {foo: [' Bar ', ' Baz ']} will be serialized into Foo[]=bar&foo[]=baz instead of serialized into previous Foo=bar&foo=baz.

If you want to use the old serialization method, there are three ways to set it up:
Copy Code code as follows:

JQuery.ajaxSettings.traditional = true;
Jquery.param (stuff, true);
$.ajax ({data:stuff, traditional:true});

2 automatically detects the data types of JSON and JavaScript.
After 1.4 returns JSON or JavaScript can not be set datatype, will automatically judge the type according to Application/json or Application/x-javascript. However, the data types returned in the background must be specified.

3 support for adding HTML header information.
$.ajax () Adds a new property ifmodified:true, set to true, to efficiently use the browser cache (I've tried to do that now.) )

4 Use native Json.parse to parse json.
1.4 Verifies the validity of the Ajax returned JSON, and the wrong JSON format will not parse, such as {foo: "Bar"}.

5 $.serialize () when serializing a form, you can now serialize HTML5 form elements.
...... Quite with the times, HTML5 I have not seriously read ...

6 Note Add a new attribute context, very useful
The context is so timely that the context simplifies your AJAX requests. The role of the context is that you can customize the contexts that specify this for the callback function in Ajax. Look at the code:
Copy Code code as follows:

Jquery.ajax ({
URL: "Test.html",
Context:document.body,
Success:function () {
JQuery (This). AddClass ("Done");
}
});

The This in the code success callback function points to document.body

7 Explicitly set Content-type
Before 1.4, if you do not set the parameter Data,$.ajax () will ignore the value of contenttype this parameter, 1.4contentType in the AJAX request to send.

8 You can specify the name of the callback function of the JSONP
9 cross-domain requests are not allowed by default
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.