Javascript 成功提交ajax表单后停止Ladda按钮旋转
我有以下代码用于将表单数据提交到post_receiver.phpJavascript 成功提交ajax表单后停止Ladda按钮旋转,javascript,php,jquery,ajax,twitter-bootstrap,Javascript,Php,Jquery,Ajax,Twitter Bootstrap,我有以下代码用于将表单数据提交到post_receiver.php <html> <head> <title>jQuery post form data using .post() method by codeofaninja.com</title> </head> <body> <h1>jQuery post form data using .post() method<
<html>
<head>
<title>jQuery post form data using .post() method by codeofaninja.com</title>
</head>
<body>
<h1>jQuery post form data using .post() method</h1>
<div>Fill out and submit the form below to get response.</div>
<!-- our form -->
<form id='userForm'>
<div><input type='text' name='firstname' placeholder='Firstname' /></div>
<div><input type='text' name='lastname' placeholder='Lastname' /></div>
<div><input type='text' name='email' placeholder='Email' /></div>
<div><input type='submit' value='Submit' /></div>
</form>
<!-- where the response will be displayed -->
<div id='response'></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>
<script>
$(document).ready(function(){
$('#userForm').submit(function(){
// show that something is loading
$('#response').html("<b>Loading response...</b>");
/*
* 'post_receiver.php' - where you will pass the form data
* $(this).serialize() - to easily read form data
* function(data){... - data contains the response from post_receiver.php
*/
$.post('post_receiver.php', $(this).serialize(), function(data){
// show the response
$('#response').html(data);
}).fail(function() {
// just in case posting your form failed
alert( "Posting failed." );
});
// to prevent refreshing the whole page page
return false;
});
});
</script>
</body>
</html>
codeofaninja.com使用.post()方法查询post表单数据
jQuery使用.post()方法发布表单数据
填写并提交以下表格以获得回复。
$(文档).ready(函数(){
$('#userForm')。提交(函数(){
//显示有东西正在加载
$('#response').html(“加载响应…”);
/*
*“post_receiver.php”-您将在其中传递表单数据
*$(this).serialize()-轻松读取表单数据
*函数(data){…-数据包含来自post_receiver.php的响应
*/
$.post('post_receiver.php',$(this).serialize(),函数(数据){
//显示响应
$('#response').html(数据);
}).fail(函数(){
//以防你的表格发布失败
警报(“发布失败”);
});
//防止刷新整个页面
返回false;
});
});
这段代码没有问题。但是我使用Ladda按钮来显示submit按钮的旋转效果(这个:),我希望这个效果在结果返回后立即停止
我在这个网站上搜索并找到了一些类似问题的答案,但作为一个对Javascript和Ajax几乎一无所知的新手,我仍然无法解决我的问题
因此,请有人告诉我需要插入更多的代码。感谢您的帮助!您可能应该在
$('#response').html(数据);
之后添加l.stop()
,但这取决于您如何初始化Ladda
如果它不起作用,也发布代码。在
$的末尾添加一个.always()
。发布并使用stop()
停止旋转。您链接的页面底部有示例代码。看到这个答案是最近的,但我仍然需要说声谢谢。解决方案已接受!