Hello,
I have one issue in code which I could not figure out. I'm making esriRequest function. Code details:
var req = EsriRequest({ url: lyrIdUrl, content: { f: "json" }, handleAs: "json", callbackParamName: "" },
{ usePost: true });
req.then(function (response) {
debugger;
geotypeJson = response;
alert("Succeess");
}, function (error) {
console.log(error.message);
alert("ID Error");
});
debugger;
For some reason code followed by req.then executes first before what's code inside req.then (I added debugger to confirm this). Can someone help me understand why? Also, can someone help me fix it, please? I want to assign geotypeJson to response from lyrIdUrl.
Meghan Kulkarni#
Meghan,
That is expected. The code following the .then is inline code that does not wait for the promise to resolve. So if you have code that is dependent on the request result then it has to inside the .then function.
Thanks Robert. Isn't my code in then function already?
req.then(function (response) {
debugger;
geotypeJson = response;
alert("Succeess");
}, function (error) {
console.log(error.message);
alert("ID Error");
});
Meghan,
So I am not sure what's the question you have then.
You will always get to the debugger statemkent outside the .then function before you get to inside the debugger (as I mentioned earlier).
Hello Robert,
Basically I want to assign geotypeJson = response; as a consequence of esriRequest execution complete.
Then you need to have anything that uses geoTypeJson wait for the .then to complete or have anything that uses it inside the .then.
Let me ask you in a bit of a different way. Is there a way to make esriRequest synchronous from default asynchronous?
Thanks.
Meghan Kulkarni
Nevermind. I found solution in the thread
https://community.esri.com/thread/190913-making-request-synchronous