Home >Web Front-end >JS Tutorial >Summary of jQuery asynchronous methods to obtain json data_jquery

Summary of jQuery asynchronous methods to obtain json data_jquery

WBOY
WBOYOriginal
2016-05-16 16:24:55953browse

There are two ways for jQuery to asynchronously obtain json data, one is the $.getJSON method and the other is the $.ajax method. This article uses these two methods to asynchronously obtain json data and then append it to the page.

Create the data.json file in the root directory:

Copy code The code is as follows:

{
"one" : "Hello",
"two" : "World"
}

■ Get json data through $.getJSON method

Copy code The code is as follows:



■ Obtain json data through $.ajax method

Copy code The code is as follows:

   
   

总结:使用$.getJSON方法和$.ajax方法都能达到相同的效果,但是,如果想对异步获取的过程有更细节的控制,推荐使用$.ajax方法。

Statement:
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