Instead of repeating the object name over and over again, you can simplify
the code with an object literal:

    $.ajax({
        type: 'GET',
        url: 'qtool',
        processData: true,
        data: {
            action: 'executeQuery',
            entity_name: queryText
        },
        dataType: 'json',
        success: function(data) {
            alert( data );
        },
        error: function( xhr, status, exception ) {
            alert( xhr.responseText );
        }
    });

If you need the object in its own variable for any reason, you can still use
the object literal:

    var params = {
        type: 'GET',
        url: 'qtool',
        processData: true,
        data: {
            action: 'executeQuery',
            entity_name: queryText
        },
        dataType: 'json',
        success: function( data ) {
            alert( data );
        },
        error: function( xhr, status, exception ) {
            alert( xhr.responseText );
        }
    };
    
    $.ajax( params );

-Mike

> From: MorningZ
> 
> Don't use the $.getJSON method as it, as you are finding out, has no
> way to handle an error...
> 
> use the generic $.ajax instead
> 
> var Params = {};
> Params.type = "GET";
> Params.url = "qtool";
> Params.processData = true;
> Params.data = {action: "executeQuery", entity_name: queryText };
> Params.dataType = "json";
> Params.success = function(data) {
>       alert(data);
> };
> Params.error = function(x,y,z) {
>      alert(x.responseText);
> };
> $.ajax(Params);
> 
> that way "x" will be the error response from the server (which
> apparently you are running into)
> 

Reply via email to