ThinkGeo.com    |     Documentation    |     Premium Support

ajaxCallAction error handling?

Is there any error handling possible for ajaxCallAction, for the case when the method on the backend throws an exception or otherwise encounters an error?

Hi Jay,



In Mvc Edition, If you debug into the method from the func_GeoResource.axd, you will find we are using Sys.Net.WebRequest instance to send ajax call. Here is a link about this instance: msdn.microsoft.com/en-us/li…100).aspx


ajaxCall: function (url, params, callback) {
        var wRequest = new Sys.Net.WebRequest();
        wRequest.set_url(url);
        wRequest.set_httpVerb(‘POST’);
        var mapParser = this.getMapParser();
        var param = ‘__#’ + mapParser.pageName + “|__#”;
        for (var item in params) {
            param = param + item + “:” + params[item] + ‘^’;
        }
        wRequest.set_body(param);
        wRequest.add_completed(callback);
        wRequest.invoke();
    }

In the call back parameter, you can use this parameter to access the executor that issued the request and to check its completed status and retrieve the response data. So, you can check the response status and handler the error from the server side.



If any questions, please feel free to let us know.

Thanks,

Troy