[英]Chrome duplicates ajax request or response
i'm making login form and i'm recieving duplicationg results. 我正在制作登录表单,并且正在接收重复结果。 For example. 例如。 I click login button, function: 我点击登录按钮,功能:
function PostLogin() {
var $result = $("#forms");
$.ajax({
type: "POST",
data: {
"login": $('#login').val(),
"password": $('#password').val(),
},
dataType: "html",
url: "php/login.php",
beforeSend: function() {
$result.html('<div class="alert">Подождите...</div>');
},
success: function(data) {
$result.html(data);
},
});
}
After result recieved, it is supposed to be written in <div id="forms" class = "formsdiv"></div>
收到结果后,应将其写入<div id="forms" class = "formsdiv"></div>
I see for a moment that it written, but then I have straight call of my php file: 我看了一会儿它写了,但是随后我直接调用了我的php文件:
What i get in Chrome - see image http://i.stack.imgur.com/RBiXx.png (no reputation) 我在Chrome中获得的功能-参见图片http://i.stack.imgur.com/RBiXx.png (无信誉)
Firefox works fine and i get what i want. Firefox工作正常,我得到了我想要的。
Firefox result - http://i.stack.imgur.com/xnGBZ.png Firefox结果-http://i.stack.imgur.com/xnGBZ.png
My login form: 我的登录表格:
<form id="login-form" method="post" action="php/login.php" role="form" style="display: block;">
<div class="form-group">
<input type="text" name="login" id="login" tabindex="1" class="form-control" placeholder="Логин" value="">
</div>
<div class="form-group">
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Пароль">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-login" onclick="PostLogin()" value="Войти">
</div>
</div>
</div>
</form>
Any suggestions how to make it work in chrome? 有什么建议如何使其在chrome中工作?
You should remove the action attribute from your form or add "return false;" 您应该从表单中删除action属性或添加“ return false”; to your onclick event since you are using an AJAX call and do not want the form to submit. 到onclick事件,因为您正在使用AJAX调用并且不希望提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.