2013-11-28 96 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的东西后,检查电子邮件。