How do you override an existing html form to use jquery to post the form?

前端 未结 3 1860
孤独总比滥情好
孤独总比滥情好 2021-02-05 13:23

I have a simple form that I am currently posting back to the server to update a nickname. What jquery code do I add (without changing the form) so that the page will not refresh

3条回答
  •  你的背包
    2021-02-05 14:05

    try reading this.

    or

    $("form").submit(function(e){
        var form = $(this);
        $.ajax({ 
             url   : form.attr('action'),
             type  : form.attr('method'),
             data  : form.serialize(), // data to be submitted
             success: function(response){
                alert(response); // do what you like with the response
             }
        });
        return false;
     });
    

提交回复
热议问题