Emanegux
Emanegux

Reputation: 1120

Retrieving string from a very simple json file using JQuery and jsonp

I need help with getting a simple string from a Json file on a nonlocal site using JQuery. Here is some useful information.

URL of Json File: https://targetjsonsite.com/fileofinterest.json?api_key=12341234123412341234

Contents of Json File: {"state":"finished"}

Here is my attempt-

<script>
$.getJSON("https://targetjsonsite.com/fileofinterest.json?api_key=12341234123412341234",
{
format: "json"
},
function(data) {
$.each(data.items, function(item){
//right here is where I would want to get the value "state" is set to.
});
});
</script>

I'm having trouble finding an example online that really helps me to understand what's going on. It seems like most explain how jsonp work on a very general level and then give you a very specific example that may not relate. Please help.

Upvotes: 0

Views: 144

Answers (1)

Yograj Gupta
Yograj Gupta

Reputation: 9869

You should try this

$.getJSON("https://targetjsonsite.com/fileofinterest.json?api_key=12341234123412341234",
{
format: "json"
},
function(data) { 
    //your json is returing {"state":"finished"} so data will store {"state":"finished"};
    alert(data.state);//and you want to get the state value so it will be data.state.
});

Upvotes: 1

Related Questions