我有这个代码来向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</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>
此代码没有问题。但是我正在使用 Ladda 按钮来显示提交按钮的旋转效果(这个:https://msurguy.github.io/ladda-bootstrap/(,我希望这种效果在结果返回后立即停止。
我在这个网站上搜索并找到了一些类似问题的答案,但作为一个对Javascript和Ajax几乎一无所知的新手,我仍然无法解决我的问题。
所以有人请告诉我我需要插入更多的代码。感谢您的所有帮助!
您可能应该在 $('#response').html(data);
之后添加 l.stop()
,但这取决于您如何初始化 Ladda。
如果它不起作用,也发布该代码。