function json_call_ajax(method, params, numRets, callback, errorCallback, json_rpc_context) {
        var deferred = $.Deferred();

        if (typeof callback === 'function') {
           deferred.done(callback);
        }

        if (typeof errorCallback === 'function') {
           deferred.fail(errorCallback);
        }

        var rpc = {
            params : params,
            method : method,
            version: "1.1",
            id: String(Math.random()).slice(2),
        };
        if (json_rpc_context)
            rpc['context'] = json_rpc_context;

        var beforeSend = null;
        var token = (_auth_cb && typeof _auth_cb === 'function') ? _auth_cb()
            : (_auth.token ? _auth.token : null);
        if (token != null) {
            beforeSend = function (xhr) {
                xhr.setRequestHeader("Authorization", token);
            }
        }

        var xhr = jQuery.ajax({
            url: _url,
            dataType: "text",
            type: 'POST',
            processData: false,
            data: JSON.stringify(rpc),
            beforeSend: beforeSend,
            timeout: _timeout,
            success: function (data, status, xhr) {
                var result;
                try {
                    var resp = JSON.parse(data);
                    result = (numRets === 1 ? resp.result[0] : resp.result);
                } catch (err) {
                    deferred.reject({
                        status: 503,
                        error: err,
                        url: _url,
                        resp: data
                    });
                    return;
                }
                deferred.resolve(result);
            },
            error: function (xhr, textStatus, errorThrown) {
                var error;
                if (xhr.responseText) {
                    try {
                        var resp = JSON.parse(xhr.responseText);
                        error = resp.error;
                    } catch (err) { // Not JSON
                        error = "Unknown error - " + xhr.responseText;
                    }
                } else {
                    error = "Unknown Error";
                }
                deferred.reject({
                    status: 500,
                    error: error
                });
            }
        });

        var promise = deferred.promise();
        promise.xhr = xhr;
        return promise;
    }
/*
     * JSON call using jQuery method.
     */
JSON call using jQuery method.
JSON call using jQuery method .
function json_call_ajax(method, params, numRets, callback, errorCallback, json_rpc_context) {
        var deferred = $.Deferred();
        if (typeof callback === 'function') {
           deferred.done(callback);
        }
        if (typeof errorCallback === 'function') {
           deferred.fail(errorCallback);
        }
        var rpc = {
            params : params,
            method : method,
            version: "1.1",
            id: String(Math.random()).slice(2),
        };
        if (json_rpc_context)
            rpc['context'] = json_rpc_context;
        var beforeSend = null;
        var token = (_auth_cb && typeof _auth_cb === 'function') ? _auth_cb()
            : (_auth.token ? _auth.token : null);
        if (token != null) {
            beforeSend = function (xhr) {
                xhr.setRequestHeader("Authorization", token);
            }
        }
        var xhr = jQuery.ajax({
            url: _url,
            dataType: "text",
            type: 'POST',
            processData: false,
            data: JSON.stringify(rpc),
            beforeSend: beforeSend,
            timeout: _timeout,
            success: function (data, status, xhr) {
                var result;
                try {
                    var resp = JSON.parse(data);
                    result = (numRets === 1 ? resp.result[0] : resp.result);
                } catch (err) {
                    deferred.reject({
                        status: 503,
                        error: err,
                        url: _url,
                        resp: data
                    });
                    return;
                }
                deferred.resolve(result);
            },
            error: function (xhr, textStatus, errorThrown) {
                var error;
                if (xhr.responseText) {
                    try {
                        var resp = JSON.parse(xhr.responseText);
                        error = resp.error;
                    } catch (err) { 
                        error = "Unknown error - " + xhr.responseText;
                    }
                } else {
                    error = "Unknown Error";
                }
                deferred.reject({
                    status: 500,
                    error: error
                });
            }
        });
        var promise = deferred.promise();
        promise.xhr = xhr;
        return promise;
    }
function json_call_ajax ( method , params , numRets , callback , errorCallback , json_rpc_context ) { var deferred = $ . Deferred ( ) ; if ( typeof callback === 'function' ) { deferred . done ( callback ) ; } if ( typeof errorCallback === 'function' ) { deferred . fail ( errorCallback ) ; } var rpc = { params : params , method : method , version : "1.1" , id : String ( Math . random ( ) ) . slice ( 2 ) , } ; if ( json_rpc_context ) rpc [ 'context' ] = json_rpc_context ; var beforeSend = null ; var token = ( _auth_cb && typeof _auth_cb === 'function' ) ? _auth_cb ( ) : ( _auth . token ? _auth . token : null ) ; if ( token != null ) { beforeSend = function ( xhr ) { xhr . setRequestHeader ( "Authorization" , token ) ; } } var xhr = jQuery . ajax ( { url : _url , dataType : "text" , type : 'POST' , processData : false , data : JSON . stringify ( rpc ) , beforeSend : beforeSend , timeout : _timeout , success : function ( data , status , xhr ) { var result ; try { var resp = JSON . parse ( data ) ; result = ( numRets === 1 ? resp . result [ 0 ] : resp . result ) ; } catch ( err ) { deferred . reject ( { status : 503 , error : err , url : _url , resp : data } ) ; return ; } deferred . resolve ( result ) ; } , error : function ( xhr , textStatus , errorThrown ) { var error ; if ( xhr . responseText ) { try { var resp = JSON . parse ( xhr . responseText ) ; error = resp . error ; } catch ( err ) { error = "Unknown error - " + xhr . responseText ; } } else { error = "Unknown Error" ; } deferred . reject ( { status : 500 , error : error } ) ; } } ) ; var promise = deferred . promise ( ) ; promise . xhr = xhr ; return promise ; }
JSON call using jQuery method.
JSON call using jQuery method .
// Not JSON
