繁体   English   中英

自动提交隐藏的表格值?

[英]Submit hidden form value automatically?

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

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

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

您可以在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";

<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发布以检查电子邮件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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