0

I'm developing a new map in the IMapBuilder plugin [1], but I've problems with it. I think it's more a JSON problem, I'll explain it:

I want to extract a JSON array from a.json, that is like this:

[
{"...":"...",
...},
{"...":"...",
...}
]

Now, if I go to the Chrome console and enter:

var json_array = $.getJSON('a.json'); [ENTER]

var real_array = eval(json_array.responseText); [ENTER]

I get all the objects in the real_array. The problem comes when all is toghether. When I put it in the JavaScript code, it says me that it's undefined. I've searched about it and all people say that it's about synchronization, but if I put it synchronized, it says me that it cannot be like that because the thread can't stop because it would be worse for the users. So, I don't know if it's all clear.

Thank you in advance.

[1] http://codecanyon.net/item/interactive-map-builder-for-wordpress/7229358?ref=meisterpixel

Juan
  • 23
  • 3
  • you have to consume the data in complete callback of `$.getJSON`. See docs – charlietfl Feb 18 '15 at 23:28
  • I've tried putting something like this: $.getJSON('a.json', function(data) { real_array = data; }); And it doesn't work neither – Juan Feb 18 '15 at 23:55
  • you have to use that array in the callback, ajax is asynchronous. See: http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call – charlietfl Feb 19 '15 at 00:09

0 Answers0