Jquery1.4 tutorial 2 Ajax Method Improvement

Source: Internet
Author: User
Tags html header

1. serialized nested parameters are allowed.
For example, {FOO: ["bar", "Baz"]} Will be serialized into Foo [] = Bar & Foo [] = Baz, instead of serializing it to the previous Foo = Bar & Foo = Baz.

If you want to use the old serialization method, there are three setting methods:CopyCodeThe Code is as follows: jquery. ajaxsettings. Traditional = true;
Jquery. Param (stuff, true );
$. Ajax ({data: stuff, traditional: true });

2. automatically checks the JSON and JavaScript data types.
After 1.4, JSON or Javascript is returned. You do not need to set datatype. The type is automatically determined based on application/JSON or application/X-JavaScript. The data type returned by the background must be specified.

3. html header information can be added.
$. Ajax () adds an attribute ifmodified: True, which is set to true to effectively use the browser cache (I have tried it before .)

4. Use native JSON. parse to parse JSON.
1.4 The validity of the JSON returned by Ajax is verified. The invalid JSON format is not parsed, for example, {FOO: "bar "}.

5 $. serialize () can serialize HTML5 form elements.
...... I have not carefully read HTML5 .....

6. It is very useful to add a new attribute context.
The appearance of context is so timely that context will simplify your Ajax requests. Context allows you to customize the context, that is, specify this of the callback function in Ajax. Let's look at the Code:Copy codeThe Code is as follows: jquery. Ajax ({
URL: "test.html ",
Context: Document. Body,
Success: function (){
Jquery (this). addclass ("done ");
}
});

This in the Code success callback function will point to document. Body

7 explicitly set Content-Type
Before 1.4, if you have not set the data parameter, $. Ajax () will ignore the value of contenttype, and 1.4contenttype will be sent during Ajax requests.

8. You can specify the callback function name of jsonp.
9 by default, cross-origin requests are not allowed.

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.