How to Use ajax to call json data in jquery

Source: Internet
Author: User

$. Get () and $. post () methods are basically the same, so only $. post () is used!
Scenario 1: $. post ("url", function); The returned data is not processed, so it is not in json format!
Scenario 2: $. post ("url", function, "json"); although the returned data is specified in json format, it is not actually!
Case 3: $. post ("url", {}, function); the input parameter is null and the returned data format is not specified, so it is not in json format!
Scenario 4: $. post ("url", {}, function, "json"); The json format data is returned correctly!
Key point: to process the returned data in json format, you must input a parameter (the parameter is written as {} if it is null) and specify the return type as "json "!
$. Ajax ({
Url: "url ",
DataType: "json ",
Type: "get"
Success: function
})
Key Point: To specify dataType as "json", both get and post methods will get json data. However, we recommend that you add data to the above two methods to ensure consistency:.
$. GetJSON ("url", function)
Key Point: get data in json format. It is convenient to write $. get!
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.