简体   繁体   English

PHP,JQuery表单提交重定向到另一个页面

[英]PHP, JQuery Form submit redirect to another page

I have two forms in one page, registration and login. 我在一页中有两种形式,即注册和登录。 If a user try to enter a username into the "register_username" field, then on-blur, ajax check if this username already taken. 如果用户尝试在“ register_username”字段中输入用户名,则模糊不清的ajax会检查该用户名是否已被使用。 It's all working properly. 一切正常。 but I found out that if this ajax-call has been made, and then you click submit on the login form, it's redirect to the php-ajax page instead of the form-proccess php page. 但是我发现,如果进行了此ajax调用,然后在登录表单上单击“提交”,它将重定向到php-ajax页面,而不是表单处理php页面。

I'm using Code-Ignitier as PHP framework, JQuery as javascript library and that's it. 我使用Code-Ignitier作为PHP框架,使用JQuery作为javascript库,仅此而已。 any additional information i'll try to deliver if i asked to do so. 如果需要,我将尝试提供任何其他信息。 thank you very much. 非常感谢你。

Edit: //Javascript code: 编辑: // Javascript代码:

$('#register_username').live('blur',function() {
 $.post('ajax/username_taken', {'register_username':$(this).val() },
 function(result) {
  if(result) {
   $('#register_username').addClass('error');
  }
  else {
   $('#register_username').removeClass('error');
  }
 });
}

//Php code // Php代码

echo form_open('form/login',$form_attr);
echo ....
echo form_submit($submit_attr);
echo form_close();
echo form_open('form/register',$form_attr);
echo ....
echo form_submit($submit_attr);
echo form_close();

NOTE: This is all simplified, the forms are actually on different views, only register has a controller 注意:这都是简化的,表格实际上在不同的视图上,只有寄存器有一个控制器

I'm just blind-guessing since you didn't provide much info. 我只是在猜测,因为您没有提供太多信息。 It seems that your javascript overrides your submit button's click event so try adding this in your function(result) and see if anything changes: 看来您的JavaScript会覆盖您的“提交”按钮的click事件,因此请尝试将其添加到您的function(result) ,看看是否有任何变化:

$('submit_button_selector').unbind();

Ofcourse, change $('XXX') part with your button selector, generally it should be like $('#my_form).find(':submit') 当然,用按钮选择器更改$('XXX')部分,通常应该像$('#my_form).find(':submit')

Its really a blindshot and more info would help a lot. 它确实是一个盲点,更多信息会有所帮助。

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

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