【问题标题】:what's the different between $.ajax(...type: "POST", dataType: "JSON"...) and $.post(..., "JSON")$.ajax(...type: "POST", dataType: "JSON"...) 和 $.post(..., "JSON") 有什么区别
【发布时间】:2010-07-06 19:50:34
【问题描述】:

我可以使用 $.post() 解析返回的 json 字符串,但不能使用 $.ajax()。

{"result": "success", "id": "1"}

【问题讨论】:

  • 请出示您的代码。

标签: jquery ajax json post


【解决方案1】:

post 的实际代码是:

post: function( url, data, callback, type ) {
    // shift arguments if data argument was omited
    if ( jQuery.isFunction( data ) ) {
        type = type || callback;
        callback = data;
        data = {};
    }

    return jQuery.ajax({
        type: "POST",
        url: url,
        data: data,
        success: callback,
        dataType: type
    });
},

正如文档所说,它只是 $.ajax 的简写

【讨论】:

    猜你喜欢
    • 2013-10-06
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 2012-06-06
    • 2013-04-15
    • 2014-08-10
    相关资源
    最近更新 更多