D555 D555 - 3 years ago 145
Javascript Question

Jquery ajax error callback is executed even though the response http status is 200

I have written simple ajax code, in success callback I have written an alert but it does not work.

The code is:

var id = $(this).attr('data-transaction_id');
//var ttype = $(this).attr('data-ttype');
if (confirm("Are you sure you want to mark this transaction as complete?")) {
url:"<?php echo Yii::app()->getBaseUrl(true);?>/customer/changeForexTransactionStatus",
dataType: "json",
if(res == "unauthorized"){
alert("You Are not authorize to perform this action.");

if(res == "success"){
} else if(res == "insufficient_fund"){
alert('Insufficient Fees');
} else if(res == 'invalid_fee_account'){
alert('Invalid Merchant Fees Account');
error:function(t) {

Even though the response http status code is 200, it goes into error callback whereas it should have gone in success callback and opened an alert box.

Can anyone please help on this.

Answer Source

You are expecting json back not text so change the ajax dataType to text

 dataType: "text",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download