自动提交隐藏表单值

Submit hidden form value automatically?

本文关键字:表单 隐藏 提交      更新时间:2023-12-13

如何自动提交表单的特定部分,而不刷新具有需要发送到服务器的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 post来检查电子邮件。