Select to view content in your preferred language

esri.request method not returning deferred object

4012
2
Jump to solution
06-06-2013 08:35 PM
ZorbaConlen
Deactivated User
Hi,
I'm using esri.request method to do adds, deletes, edits to a feature service in my app. And to add attachments. The behavior I'm experiencing is that the callback functions I am defining are fired immediately instead of waiting for the request to complete. The callback function for successful requests is supposed to refresh the map service, which it does, but too soon, and thus does not display the new data. Also, the function for failed requests gets fired even on successful requests.

Here is an example section of code:
function delIncident() {   var feature = map.infoWindow.getSelectedFeature();    var incidentID = feature.attributes.incidentID;   var url = esri.urlToObject("http://.../FeatureServer/1/applyEdits?deletes=" + String(incidentID) + "&f=json");   var requestHandle = esri.request({      url: url.path,     content: url.query       }, {useProxy:true, usePost:true});      requestHandle.then(reqSucceeded('delIncident'),       reqFailed('delIncident')     ); }


I can make this work by using the javascript setTimeout method (to have the callback methods called only after a short delay), but I believe I should not have to do this.

The weird part is that this was all working as expected at one point. Perhaps something I changed in another part of the code caused this but I can't find it if so.

Using AGS 10.0 and jsapi 2.8.

Anyone have an idea what's wrong here?

Thanks.
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
You are invoking your functions instead of passing them as arguments (callbacks) to esri/request's then method.

Here's passing your functions as arguments:
requestHandle.then( reqSucceeded, reqFailed );


Here's what you're doing:
requestHandle.then( reqSucceeded('delIncident'), reqFailed('delIncident') );


See the difference?

If you need to inject arguments to reqSucceeded and/or reqFailed, use lang.partial.

View solution in original post

0 Kudos
2 Replies
derekswingley1
Deactivated User
You are invoking your functions instead of passing them as arguments (callbacks) to esri/request's then method.

Here's passing your functions as arguments:
requestHandle.then( reqSucceeded, reqFailed );


Here's what you're doing:
requestHandle.then( reqSucceeded('delIncident'), reqFailed('delIncident') );


See the difference?

If you need to inject arguments to reqSucceeded and/or reqFailed, use lang.partial.
0 Kudos
ZorbaConlen
Deactivated User
Ok, I see. Thanks for the tip.
0 Kudos