2017-04-08 62 views
0

HII傢伙進出口新的網絡編程和IM在這個網站建立一個網站 刷新頁面,我想添加聯繫人我們在頁面這樣不要當您提交表單

<form action="footer_contactus1.php" method="post"> 
    <div class="row"> 
    <div class="form-grope col-lg-4"> 
     <label><span class="glyphicon glyphicon-user"></span>Name</label><br> 
     <input name="cuname" type="text" class="form-cotrol"> 
    </div> 
    <div class="form-grope col-lg-4"> 
     <label><samp class="glyphicon glyphicon-envelope"></samp>Email</label><br> 
     <input name="cuemail" type="email" class="form-cotrol"> 
    </div> 
    <div class="form-grope col-lg-4"> 
     <label><i class="glyphicon glyphicon-earphone"></i>Phone Number</label><br> 
     <input name="cutele" type="tel" class="form-cotrol"> 
    </div> 

    <div class="form-grope col-lg-12"> 
    <br> 
     <label><span class="glyphicon glyphicon-paste"></span>Message</label><br> 
     <textarea name="cumessage" class="form-cotrol" rows="6" style="width: 100%;" ></textarea> 
    </div> 
    <div class="form-grope col-lg-12"> 
    <br> 
     <input type="hidden" name="save" value="contact"> 
     <button type="submit" class="btn btn-info">Submit</button> 
    </div> 
    </div> 
</form> 
頁腳形成

,當我點擊提交按鈕我想執行的PHP文件,使輸入得到了插入到數據庫 php文件

<?php 

$pdo = new PDO('mysql:host=localhost;dbname=mywsite_db', 'root', ''); 

$req = $pdo->prepare('INSERT INTO message (id_message,nom,email,tele,message) 
VALUES(null,?,?,?,?)'); 
$req->execute(array($_POST['cuname'],$_POST['cuemail'],$_POST['cutele'],$_POST['cumessage'])); 

header('Location: HomePage.php'); 

?> 

我想獲得無阿賈克斯刷新頁面submited這種形式我嘗試了不同的教程,沒有任何工作可以讓你的靈感給我正確的ajax腳本爲我的形式,所以我可以提交給PHP文件,並在數據庫中插入數據然後彈出一條消息(警報)彈出告訴我,數據已一直沒有刷新頁面plzz

回答

1
<form action="footer_contactus1.php" method="post" id="myForm1"> 
    ... 
</form> 

<script type="text/javascript"> 
    var frm = $('#myForm1'); 
    frm.submit(function (ev) { 
     $.ajax({ 
      type: frm.attr('method'), 
      url: frm.attr('action'), 
      data: frm.serialize(), 
      success: function (data) { 
       alert('The data has been inserted'); 
      } 
     }); 

     ev.preventDefault(); 
    }); 
</script> 
+0

謝謝你這麼多人你是一個生活救星 –