How do I call the REST API https://www.arcgis.com/sharing/generateToken?username=<>&password=<>&referer=https://geoenrich.arcgis.com&f=json from a javascript method? I tried using jquery ajax request and found it working sometime and sometime the request is always pending.
And for the the following url, I do not find any specific query that I need to use? In Arc GIS 3.19 version I saw esri.tasks.locationproviders.StandardGeographyQueryLocationProvider but in 4 it is not there. If I make normal ajax call using jquery it does not work at all.
Please help me to resolve the problem.
In the "then" part of the esri.request
console.log(resp); should be console.log(response.data);
or
your resp = response.data must be defined before the console.log(resp); output.
The return resp; might also return nothing, because the request has not completed yet.
Hi Basson,
That part of code is typo. What exactly iwant is the following two lines need to be executed:
var myResp = myTestFunction('myuname','mypass');
console.log(myResp);
Do it like in Robert's example where the result is returned in the showResults function then instead of
var myResp = myTestFunction('myuname','mypass');
console.log(myResp);
just do
myTestFunction('myuname','mypass');
and change the request "then" function to
.then(function(response){
showResults(response);
}
i need to store the response and use it in some other method. Thats the reason I want to do it that way.
No problem - make resp a global variable which you assign the value to in the showResults function.
My requirement is to fetch the data. and use it somewhere else.
I should have the method to call using ESRI API in a separate class and then call that from other class.
Roshni, I think your original question has been answered and solved. You'll have to figure out a way to pass the variable data between functions.
Ok. Thanks so much for all the help.
If any of you come across to the kind of issue I'm facing please provide suggestion.
This is a very helpful example for me too! It does pull in that data successfully, however I am also showing a CORS error in the console. Should that not be appearing with examples? I also have it after this tutorial Get an access token | ArcGIS for Developers and this tutorial Query a feature layer | ArcGIS for Developers .