Skip to content

Commit eb91639

Browse files
authored
Jquery JSON to external variable
This function can assign a json request into external variable . The main issue being that $.getJSON will run asynchronously, thus your Javascript will progress past the expression which invokes it even before its success callback fires, so there are no guarantees that your variable will capture any data. Note: this function will fire a warning console into the web browser "By default, all requests are sent asynchronous (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active."
1 parent 7b99dcd commit eb91639

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

getJson_to_ext_var.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var json = (function () {
2+
var json = null;
3+
$.ajax({
4+
'async': false,
5+
'global': false,
6+
'url': mapas[j],
7+
'dataType': "json",
8+
'success': function (data) {
9+
json = data;
10+
}
11+
});
12+
return json;
13+
})();

0 commit comments

Comments
 (0)