Submit form without page reloading

后端 未结 17 2795
无人及你
无人及你 2020-11-22 00:45

I have a classifieds website, and on the page where ads are showed, I am creating a \"Send a tip to a friend\" form...

So anybody who wants can send a tip of the ad

17条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:34

    You'll need to submit an ajax request to send the email without reloading the page. Take a look at http://api.jquery.com/jQuery.ajax/

    Your code should be something along the lines of:

    $('#submit').click(function() {
        $.ajax({
            url: 'send_email.php',
            type: 'POST',
            data: {
                email: 'email@example.com',
                message: 'hello world!'
            },
            success: function(msg) {
                alert('Email Sent');
            }               
        });
    });
    

    The form will submit in the background to the send_email.php page which will need to handle the request and send the email.

提交回复
热议问题