Parsing JSON from a URL

I am creating a website and I am using a URL that returns a JSON response, for example:

{name:mark; status:ok} 

I would like to get the name using only JavaScript or jQuery in my HTML page.

Can someone help me do this?

+4
source share
3 answers

Take a look at the jQuery .getJSON() method, which will make it very easy for you.

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

If you need more flexibility, you should take a look at .ajax() . .getJSON() is actually just a short hand for the .ajax() method, suitable for simple JSON fetch requests. Using .ajax() you will have many other options - for example, specifying an error handler and much more.

+7
source
 $.getJSON("URL", function(json) { alert("JSON Data: " + json.name); }); 

I think this will work for you.

If you want to pass parameters, here is the code

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

Refer link

+3
source
  $(document).ready(function () { var url = 'https://graph.facebook.com/me'; $.getJSON(url, function (data) { alert(data.name); }); }); 
0
source

Source: https://habr.com/ru/post/1394754/


All Articles