自动提交隐藏的表格值?

时间:2013-11-28 07:04:06

标签: javascript jquery forms

如何自动提交表单的特定部分但不刷新包含我需要发送给服务器的value属性的页面?

我需要这样做的原因是不断检查我的数据库中的电子邮件地址是否匹配,但没有刷新页面....

我知道我可以使用set interval来每0.25秒触发一次函数但是我应该插入什么才能将我的属性发送到服务器?

2 个答案:

答案 0 :(得分:1)

您可以在jquery中使用on 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 :(得分: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发帖来检查电子邮件。