使用 XAJAX 验证表单

发布于 2024-08-05 23:45:03 字数 467 浏览 3 评论 0原文

我使用 jQuery 来识别用户何时提交了表单。然后,我使用 xajax 调用 php 方法来查询数据库,并确保用户名和电子邮件地址尚未使用。


  $('#newUserForm').submit(function() {
      var FormName = $(this).attr('name');
      xajax_validateEmailAddressAndUsername(xajax.getFormValues(FormName));
  });

<代码> 然后在 validateEmailAddressAndUsername 中,我查询数据库并以这种方式进行验证。

我遇到的问题是 jquery 是异步的,我无法在提交表单之前添加具有正确 xajax 响应的脚本。我该如何解决这个问题?
我应该用不同的方式来做吗?

谢谢

I am using jQuery to identify when a user has submitted the form. Then I call, using xajax, a php method to query the database and make sure that the usename and email address are not already in use.


  $('#newUserForm').submit(function() {
      var FormName = $(this).attr('name');
      xajax_validateEmailAddressAndUsername(xajax.getFormValues(FormName));
  });


Then in validateEmailAddressAndUsername I query the database and validate this way.


The problem that I have encounter is that jquery is asynchronous, and there is no way for me to add a script with the right xajax response before the form gets submitted. how can I address this problem?
should I do it in a different way?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-08-12 23:45:03

有时我在仅使用 #(obj).submit() 时遇到麻烦。 .bind 似乎更可靠。
我认为你可以做这样的事情(未经测试):

$('#newUserForm').bind('submit', function() {
     var FormName = $(this).attr('name');
     if (xajax_validateEmailAddressAndUsername(xajax.getFormValues(FormName))) {
          $(this).submit();
     }
     else {
         alert("Oh no!"); 
         return false;
     }
}

I sometimes have trouble with just using #(obj).submit(). .bind seems to be more reliable.
You could do something like this I think (untested):

$('#newUserForm').bind('submit', function() {
     var FormName = $(this).attr('name');
     if (xajax_validateEmailAddressAndUsername(xajax.getFormValues(FormName))) {
          $(this).submit();
     }
     else {
         alert("Oh no!"); 
         return false;
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文