Home > Web Front-end > JS Tutorial > body text

Instructions for using ajax to call json data in jquery_jquery

WBOY
Release: 2016-05-16 18:09:13
Original
1027 people have browsed it

The two methods $.get() and $.post() are basically used the same way, so I only talk about $.post()!
Scenario 1: $.post("url",function); The data returned at this time has not been processed, so it is not in json format!
Scenario 2: $.post("url",function, "json"); Although the returned data is specified to be in json format, it is actually not!
Case 3: $.post("url",{},function); The parameter passed in at this time is empty, and the returned data format is not specified, so it is not in json format!
Scenario 4: $.post("url",{},function, "json"); correctly returns data in json format!
Key points: When you want to process the returned data as json format, you must pass in parameters (if the parameters are empty, write {}), and you must also specify the return type as "json"!
$.ajax({
url:"url",
dataType:"json",
type:"get"
success:function
})
Key points: To specify dataType as "json", you will get json format data regardless of the get or post method. However, I suggest that in order to be consistent with the above two methods, it is best to add the condition data: {}.
$.getJSON("url",function)
Key point: Obtaining json format data through get is a convenient way of writing $.get()!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!