ajax post within jquery onclick

前端 未结 4 1780
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 09:01

I have a button which calls a modal box to fade into the screen saying a value posted from the button then fade off, this works fine using jquery, but I also want on the sam

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-11 09:52

    You Ajax is bad formed, you need the sucsses event. With that when you invoke the ajax and it's success it will show the response.

    $.ajax
            ({ 
                url: 'reserbook.php',
                data: {"book_id":book_id},
                type: 'post',
                success: function(data) {
                    $('.modal-box').text(result).fadeIn(700, function() 
                    {
                       setTimeout(function() 
                        {
                        $('.modal-box').fadeOut();
                        }, 2000);
                    });
                  }
                 }
    

    Edit:

    Another important point is data: "book_id="+book_id, that should be data: {"book_id":book_id},

提交回复
热议问题