【发布时间】:2013-12-25 09:21:51
【问题描述】:
我正在创建简单的登录屏幕,它会在单击提交按钮时接受用户名和密码。我尝试使用 .click 但它根本不起作用,所以我使用的是 .live 但它在请求中两次传递相同的参数。
$("#loginsubmit").live('click', function (e) {
$.ajax({
url: 'auth_check.php',
data: $(loginForm1).serialize(),
type: 'POST',
cache: false,
success: function (result) {
if (result == 'success') {}
},
error: function (result) {}
});
e.preventDefault();
$.prettyPhoto.close();
return false;
});
这是我收到的请求
pusername=&ppassword=&pusername=abc&ppassword=abc
我第一次使用 jquery,在我的模板中使用了一个叫做漂亮照片的东西。 我猜这张漂亮的照片可能会引起问题。
LoginForm1 如下所示:
<div class="login_register_stuff hide"><!-- Login/Register Modal forms - hidded by default to be opened through modal -->
<div id="login_panel">
<div class="inner-container login-panel">
<h3 class="m_title">SIGN IN YOUR ACCOUNT TO HAVE ACCESS TO DIFFERENT FEATURES</h3>
<form name="loginForm1" method="post" enctype="multipart/form-data" />
<a href="#" class="create_account" onclick="ppOpen('#register_panel', '280');">CREATE ACCOUNT</a>
<input type="text" name="pusername" class="inputbox" placeholder="Username" />
<input type="password" name="ppassword" class="inputbox" placeholder="Password" />
<input type="submit" id="loginsubmit" name="loginsubmit" value="LOG IN" />
</form>
<div class="links"><a href="#" onclick="ppOpen('#forgot_panel', '350');">FORGOT YOUR USERNAME?</a> / <a href="#" onclick="ppOpen('#forgot_panel', '350');">FORGOT YOUR PASSWORD?</a></div>
</div>
漂亮的照片部分sn-p
enter <!-- prettyphoto scripts & styles -->
function ppOpen(panel, width){
jQuery.prettyPhoto.close();
setTimeout(function() {
jQuery.fn.prettyPhoto({social_tools: false, deeplinking: false, show_title: false, default_width: width, theme:'pp_kalypso'});
jQuery.prettyPhoto.open(panel);
}, 300);
} // function to open different panel within the panel
jQuery(document).ready(function($) {
jQuery("a[data-rel^='prettyPhoto'], .prettyphoto_link").prettyPhoto({theme:'pp_kalypso',social_tools:false, deeplinking:false});
jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:'pp_kalypso'});
jQuery("a[data-rel^='prettyPhoto[login_panel]']").prettyPhoto({theme:'pp_kalypso', default_width:800, social_tools:false, deeplinking:false});
jQuery(".prettyPhoto_transparent").click(function(e){
e.preventDefault();
jQuery.fn.prettyPhoto({social_tools: false, deeplinking: false, show_title: false, default_width: 980, theme:'pp_kalypso transparent', opacity: 0.95});
jQuery.prettyPhoto.open($(this).attr('href'),'','');
});
});
这里
你能帮我找出问题吗?
【问题讨论】:
-
至少使用 .on - .live 已弃用。表单是什么样子的,它在 chrome 的检查元素中是什么样子的?
-
loginForm1在您的代码中是什么样的? -
e在您的代码中是undefined。您的点击处理程序应该接受事件对象,然后您就可以使用它了。 -
@BlackSheep:会的,但是代码甚至没有达到 preventDefault,它的 ajax 请求还没有完成
-
我认为您将 name 属性放在与输入名称相同的标签上
标签: php jquery prettyphoto