Submit a php form and display its result on div without reloading page

前端 未结 5 476
北恋
北恋 2021-02-04 22:25

First of all, thank you for your kind help.

I have tried almost everything I found on stackoverflow but I cannot get this to work.

I created a form to send a te

5条回答
  •  攒了一身酷
    2021-02-04 23:20

    The problem is that when you add sendText.php as the action, your jQuery will execute because the form is submitted so that will work... BUT it will also take you to the page of the form's action field. What you want to do is not call submit but just make a button instead and have the jQuery listen to a click on that button.

    Instead of:

    
    

    Change it to a regular button:

    
    

    Then in your jQuery, change the line

    $('#contact-form').submit(function() {
    

    to

    $('#submit-button').click(function() {
    

    Also, change appendTo to html and then the result should show up in your result div.

    ----EDIT----

    This worked for me:

    
    
    
    *indicates a required field

提交回复
热议问题