【问题标题】:TypeError: $.post(...).success is not a function [duplicate]TypeError:$.post(...).success 不是函数 [重复]
【发布时间】:2017-09-24 20:58:21
【问题描述】:

有人可以帮我编写下面的代码吗?在 Firefox 开发人员工具中,我收到错误消息::TypeError: $.post(...).success is not a function

所有变量都是从表单页面提交的..

任何意见和建议将不胜感激......

谢谢

$(document).ready(function(){

    $('#post-comment-btn').click(function(){

        var _comment = $('#comment-post-text').val();
        var _userId = $('#userId').val();
        var _userName = $('#userName').val();

        if(_comment.length > 0 && _userId != null) {

            $.post("ajax/comment_insert.php",

                {
                    task : "comment_insert",
                    userId : _userId,
                    comment: _comment,


                }
                ).success(
                    function(data)
                {
                    console.log("ResponseText:" + data);
                }

                );


            console.log(_comment + " Username: " + _userName + " User Id: " + _userId);

        } else {

            console.log("The text area is empty..");

        }

        $('#comment-post-text').val("");


    });

});

【问题讨论】:

标签: javascript jquery


【解决方案1】:

不再有$.post().success方法,该函数返回一个promise,可以与donefailalwaysthen等一起使用,但不能与success一起使用

$.post("ajax/comment_insert.php", {
    task    : "comment_insert",
    userId  : _userId,
    comment : _comment,
}).done(function(data) {
    console.log("ResponseText:" + data);
});

jQuery 中所有 ajax 方法的文档现在明确指出

jqXHR.success()jqXHR.error()jqXHR.complete() 回调 从 jQuery 3.0 开始删除方法。您可以使用jqXHR.done()jqXHR.fail()jqXHR.always() 代替。

【讨论】:

    猜你喜欢
    • 2020-05-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    相关资源
    最近更新 更多