2013-11-28 98 views
0

如何自動提交表單的特定部分,但不刷新帶有需要發送給服務器的值屬性的頁面?自動提交隱藏的表單值?

我之所以要做到這一點是要不斷檢查來自我的數據庫,但沒有刷新頁面電子郵件地址的匹配....

我知道我可以使用設置的時間間隔觸發功能每隔0.25秒調度但我還應該插入什麼,以便我的屬性將發送到服務器?

+1

最好的方法是使用jQuery + AJAX http://api.jquery.com/jQuery.ajax/ – Deryck

+0

您應該使用'$ .ajax()'或相關方法從服務器請求信息。如果使用正確,Ajax將阻止頁面刷新:-) – devnull69

+0

使用此插件。 [jquery窗體](http://malsup.com/jquery/form/) –

回答

1

您可以使用jquery中的keyup事件來獲取輸入字段中的文本,並通過ajax請求將其發送到服務器。

<input type="text" id="email"> 

<script> 
    $("#email").keyup(function(){ 

    $.ajax({ 
    url: "server_script.php?email="+encodeURIComponent($(this).val()), 
    context: document.body 
    }).success(function(response) { 
     // Server response will come here on success 
     // Do what ever you like with the response 
    }); 

}); 
<script> 

而在服務器端獲取使用$_GET['email']的電子郵件,一旦確認完成後不喜歡echo "success";

1
<input id = "email"> 
<script> 
$('#email').keydown(function(e){ 
    var email_value = e.target.value; 
    $.post("ur backend url", { "email": email_value }).done(function(data){ 
      //respond here 
     }); 
}); 
</script> 

使用的keydown觸發和Ajax的東西后,檢查電子郵件。