$ .ajax成功回调错误:报告失败

时间:2014-12-28 06:19:14

标签: javascript jquery ajax

我有以下jquery。当我在回调函数中设置断点时,它会调用错误回调,虽然状态字段是200.我确定这对我来说是愚蠢的,但我看不到它。感谢。

我根据jquery文档修改了错误函数,现在我发现错误将自己标识为解析错误(SyntaxError:Unexpected token<)。响应是html(它显示正确),错误表明我需要修改数据类型信息,以便接受。怎么样?

$.ajax({
    url: "../php/recordInteraction.php",
    type: 'GET',
    data : {
        'rId' : 'image'
    },
    dataType: 'json',
    success: function(response){
        switch(response.status){
        case 'saved':
            alert(response.message); // do what you want
            break;
        case 200 :
                    $("#view1").html(arg.responseText);
            alert(response.message); // do what you want
            break;
        case 'empty':
            alert(response.message);
            break;
        default:
            alert("unknown response");
        }
    },
    error:function( jqXHR, textStatus, errorThrown){  // updated in edit.
        alert("failure" + textStatus);
        $("#view1").html(jqXHR.responseText);
    }
});

1 个答案:

答案 0 :(得分:0)

问题是指定dataType:json。将此更改为html修复了问题。