简体   繁体   中英

How can I show PHP echo in DIV through jQuery without page refresh

I would like to make the PHP echo I have appear in the div "preview". I want this because I don't want the page to refresh but to make the div "formbox" disappear and to show the echo in the "preview" div.

Does someone know what I am doing wrong?

HTML

    <div id="preview"> </div>  
 <div id="formbox">
   <form id="form" method="post" action="contactengine.php">
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" />

    <label for="City">City:</label>
    <input type="text" name="City" id="City" />

    <label for="Email">Email:</label>
    <input type="text" name="Email" id="Email" />

    <label for="Message">Message:</label><br />
    <textarea name="Message" rows="20" cols="20" id="Message"></textarea>

    <input type="submit" name="submit" value="Submit" class="submit-button" />
   </form> 
 </div> 

jQuery

   $('document').ready(function(){
     $('#form').ajaxForm( {
            target: '#preview', 
            success: function() { 
            $('#formbox').slideUp('fast'); 
            } 
        }); 
     });

PHP

if ($success){
  echo "<h1>Thank You!";
}

Just use the result.

$('document').ready(function(){
 $('#form').ajaxForm( {
        target: '#preview', 
        success: function( result ) { 
        $('#formbox').slideUp('fast'); 
        $('#preview').html(result);
        } 
    }); 
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM