Cannot change button value by ajax

前端 未结 4 1624
你的背包
你的背包 2020-12-22 00:51

After applying the http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css and http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js

the text of the

4条回答
  •  渐次进展
    2020-12-22 01:15

    By the time the AJAX callback runs, this as a keyword has lost its context. You need to assign it to a variable to retain the reference. Something like this:

    $(document).ready(function () {
        $('#submit_btn').click(function (e) {
            e.preventDefault();
            var button = $(this);
            button.val('Processing ...');
            $.ajax({
                cache: false,
                type: "POST",
                dataType: "json",
                data: $('#form1').serialize(),
                url: "echo/json",
                complete: function (HttpRequest, textStatus) {
                    button.val('Create');
                }
            });
            return false;
        });
    });
    

提交回复
热议问题