0

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.

1 Answer 1

1

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.
});
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. I had no idea it was that simple. Now I have a very very straight forward example of Jsonp I can use to build on. Thank you Yograj Gupta!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.