Parse JSON from URL

后端 未结 3 1711
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 04:46

I am building a web site and I use a url which returns a JSON response, like:

{name:mark; status:ok}

I would like to obtain the name, using onl

相关标签:
3条回答
  • 2021-02-10 04:52

    Have a look at jQuery's .getJSON() method, which will make it really easy for you.

    $.getJSON('yourURL.php', function(data) {
      alert(data.name);
    });
    

    If you need more flexibility you should have a look at .ajax() instead. .getJSON() is really just a short hand for the .ajax() method, suitable for making simple requests to fetch JSON. With .ajax() you will have a lot of more options - specifying an error handler for instance, and much more.

    0 讨论(0)
  • 2021-02-10 04:54
       $(document).ready(function () {
        var url = 'https://graph.facebook.com/me';
        $.getJSON(url, function (data) {
            alert(data.name);
        });
    }); 
    
    0 讨论(0)
  • 2021-02-10 05:18
    $.getJSON("URL", function(json) {
       alert("JSON Data: " + json.name);
     });
    

    I guess this will work for you.

    If you want to Pass parameters then here is code

    $.getJSON("URL", { name: "John", time: "2pm" }, function(json) {
        alert("JSON Data: " + json.name);
        });
    

    Refer link

    0 讨论(0)
提交回复
热议问题