How to search for JSON data in this specific code

Asked

Viewed 284 times

0

I need to do exactly as requested on this post, take Json data and return in a specific field. User Jeffson Silva did exactly what I need and made it available in this Example.

Only I ran into the following problem: I can’t find the data in an external Json for "var data = [].

I tried to use "$.getJSON("dados.json", function (data) {..." But it doesn’t work to get that data. When manually placing the array data inside "var dados = []", works but when you try to fetch this data externally, it’s not working.

Can someone give me a light and show me how to do this using this code Example?

Thanks in advance

  • That link you have indicated has an invalid JSON. It lacks the last one }.

1 answer

0


Modern browsers block asynchronous cross-Omain requests (between different domains). But there is a "hack" to circumvent this, is a data transmission technique called jsonp.

Here you can see the explanation of what it is, and at that link you see how to make jsonp requests with ajax. You will need to modify your server output as well.

If you run the script within the domain in which json is being searched you will not encounter this problem.

  • the Json file is on the same server, but, I didn’t test the code I mentioned above in my official code, but only in Jsfiddle, is that why it didn’t work?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.