doyler
doyler

Reputation: 147

Why is my json request erroring instead of succeeding?

Here is my debugging method that goes to the error block instead of the success block.

function removerelationship(reference_related_id_var) {
            if ($('##relationships').attr('id') != undefined) {
                $.ajaxSetup({cache:false});
                $.ajax({
                    url: 'index.cfm?action=reference.confirmjson',
                    dataType: 'json',
                    data: {reference_id:reference_id_var, reference_related_id:reference_related_id_var},
                    success: function(){alert("I PASSED");},
                    error: function(){alert("I FAILED");}
                    });

But this is my response from calling reference.confirmjson:

{"MESSAGE":"Are You Sure You Want To Remove The Relationship Between References 744094 and 1200?","CONFIRMED":true}

Is there some reason this would still take me to the error block?

Thanks.

Upvotes: 0

Views: 164

Answers (2)

Bradley Moore
Bradley Moore

Reputation: 748

Make sure you have debug output turned off for the AJAX request . I explain it a bit better at http://orangexception.com/post/7308110027/remove-debug-output-from-ajax-requests-in-coldfusion

Upvotes: 2

Nic Tunney
Nic Tunney

Reputation: 21

The error case would be called if any status other than a 200 is being returned. Take a peek at the response in Firebug or a similar tool. If CF is also throwing an error further down the request, it would return a 500. This can help you determine if you need to check the CF application log for an error.

Edit: Also, check the raw response. Firebug does an awesome job at dropping the trailing CF error and just showing the properly formatted JSON, which could be confusing if an error was thrown.

Upvotes: 2

Related Questions