无法使用jquery $ .post检索json结果

时间:2011-09-09 18:10:55

标签: jquery ajax json

我需要使用jqueries $ post方法并检索json结果。我已成功使用了 $ .getJSON方法如下:

$.getJSON("test_file.php", $("#test_file_form_id").serialize(), function(data){
    if (data.error) {
        alert(data.error);
    }
});

我正在我的PHP文件中返回值,如下所示:

    $res->error = "ERROR";
    echo json_encode($res);

当我尝试通过$ .post命令执行此操作时,我收到错误:对象json没有方法'apply'

以下是使用$ .post

的同一个电话
$.post("test_file.php", $("#test_file_form_id").serialize(), function(data){
    if (data.error) {
        alert(data.error);
    }
}, "json");

我错过了什么?

0 个答案:

没有答案