Send post data from html FORM with Javascript?

后端 未结 5 1035
眼角桃花
眼角桃花 2020-12-16 06:27

I am trying to send post data from from with empty action and send the info with javascript to the file that must handle the post information.

Here is my code:

5条回答
  •  渐次进展
    2020-12-16 07:05

    You're quite lucky because there's a JQuery function called "Ajax" which handles this for you!

    All you need to do is call JQuery, and use code like this:

    $('#form_id').on('submit', function(e){
        e.preventDefault();
        $.ajax({
           type: "POST",
           url: "/postinfo.php",
           data: $(this).serialize(),
           success: function() {
             alert('success');
           }
        });
    });
    

提交回复
热议问题