0

I'm trying to return a JSON from a REST endpoint server. I've tried using dom.io.script.get(), but this is used to access JSONP. dom.xhrget, is disallow for those requests on their server. My workaround in to user jQuery $.getJSON to retrieve the JSON object and return it for utilization in JavaScript. Is this possible. This is my psuedo code for this functionality.

url = http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/6?f=pjson

    function GetJson(url){
        $(document).ready(function(){
            $getJson(url, function(json){
            return json;
        });
        });

};
Parth Trivedi
  • 3,802
  • 1
  • 20
  • 40

1 Answers1

1

First of all, it is $.getJSON() and not $getJson(). You cannot return from an asynchronous call. So, to do something with the json that's returned using the $.getJSON function, you need to put it in the anonymous function there:

$.getJSON(url, function (json) {
  // The scope of json is this. You cannot return this anywhere or set anything.
  // Add your functions or instructions that use `json` here.
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252