jQuery - Send a form asynchronously

前端 未结 1 778
青春惊慌失措
青春惊慌失措 2020-12-08 02:49

I have a form such as :

相关标签:
1条回答
  • 2020-12-08 03:22
    $('form[name=contact]').submit(function(){
    
        // Maybe show a loading indicator...
    
        $.post($(this).attr('action'), $(this).serialize(), function(res){
            // Do something with the response `res`
            console.log(res);
            // Don't forget to hide the loading indicator!
        });
    
        return false; // prevent default action
    
    });
    

    See:

    • jQuery docs: post
    • jQuery docs: serialize
    0 讨论(0)
提交回复
热议问题