4

Can someone help me with my code below.. In Firefox developer tool I am getting error message: :TypeError: $.post(...).success is not a function

All variables are submitted from form page..

Any advice and suggestions will be appreciated ...

Thank you

$(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("");


    });

});
mactron
  • 61
  • 1
  • 1
  • 7
  • i mean... that function hasn't existed for a loooong time. Deprecated forever, and removed in 3.0 http://api.jquery.com/jquery.ajax/ – Kevin B Sep 24 '17 at 21:01

1 Answers1

15

There is no $.post().success method anymore, the function returns a promise, and can be used with done, fail, always, then etc, but not success

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

The documentation for all ajax methods in jQuery now clearly states that

The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callback methods are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

adeneo
  • 312,895
  • 29
  • 395
  • 388