Home  >  Article  >  Web Front-end  >  How to use jQuery getJSON() method

How to use jQuery getJSON() method

coldplay.xixi
coldplay.xixiOriginal
2020-11-24 17:29:363765browse

Usage of jQuery getJSON() method: [getJSON()] method uses AJAX HTTP GET request to obtain JSON data. The syntax is [$(selector).getJSON(url,data,success(data,status, xhr)】.

How to use jQuery getJSON() method

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, this method is suitable for all brands of computers.

Definition and usage

The getJSON() method uses AJAX's HTTP GET request to obtain JSON data.

Syntax

$(selector).getJSON(url,data,success(data,status,xhr))

Example

Use Ajax request to obtain JSON data and output the result:

$(document).ready(function(){
    $("button").click(function(){
        $.getJSON("demo_ajax_json.js",function(result){
            $.each(result, function(i, field){
                $("div").append(field + " ");
            });
        });
    });
});

How to use jQuery getJSON() method

The above is the detailed content of How to use jQuery getJSON() method. For more information, please follow other related articles on the PHP Chinese website!

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