How to fetch data in JSON in this particular code

0

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

I just ran into the following problem: I can not fetch the data in an external Json for "var data = []."

I tried to use "$.getJSON("dados.json", function (data) {..." But it does not work to get this data. When the array data is manually placed inside "var dados = []" , it works but when it tries to fetch that data it is not working.

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

Thanks in advance

    
asked by anonymous 08.04.2016 / 18:21

1 answer

0

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

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

If you run the script within the domain where json is being searched you will not find this problem.

    
08.04.2016 / 18:52