当我执行console.log(data)时,$ .ajax成功函数不会显示在控制台中;

时间:2014-08-16 14:30:06

标签: jquery ajax

在$ .ajax函数中,我有这样的成功函数:

success: function(data) {
    console.log(data);
},

但是当我使用$ .ajax函数时,它不会在控制台中显示任何内容。如果我使用$ .post函数,然后我使用console.log(数据),它将显示在控制台中,但是它不起作用,因为我在$ .post函数中不能有processData:false。

这是我的整个$ .ajax函数:

$.ajax({
    url: 'post',
    type: 'POST',
    processData: false,
    contentType: false,
    cache: false,
    dataType: 'json',
    data: formData,
    success: function(data) {
        console.log(data);
    },
    error: function() {}
});

1 个答案:

答案 0 :(得分:0)

略微改变你的代码以便在jsfiddle中运行,我没有看到任何问题(我得到Success! Object {}):

var formData = {test: 'test'};

$.ajax({
    url: '/echo/json',
    type: 'POST',
    processData: false,
    contentType: false,
    cache: false,
    dataType: 'json',
    data: formData,
    success: function(data) {
        console.log('Success!', data);
    },
    error: function(e) {
        console.log('Error!', e);
    }
});

http://jsfiddle.net/zta6ugyw/

我怀疑它是您的网址。在控制台中观看“网络”选项卡,查看您的服务器是否返回了404或其他错误。