这里是github文档:https://github.com/msurguy/ladda-bootstrap
我试图让我的代码工作但是出于某种原因,ladda不会停止旋转(按钮永远不会再次启用),即使我放置" Ladda.stopAll(); "在AJAX调用之后。这是我的代码:
<button type="button" class="btn btn-lg btn-success ladda-button" data-style="expand-left" id="genPDF"><span class="ladda-label">Generate PDF</span></button>
<script>
Ladda.bind('button[id=genPDF]');
$('#genPDF').click(function () {
//Another approach I tried
//Ladda.bind(this);
var str = "tmName=" + $("#tmName").val() +
"&headingText=" + $("#headingText").val();
$.ajax({
url: "testing.php",
data: str,
cache: false,
success: function (data) {
//None of this code matters, it all works fine
console.log(data);
var container = document.getElementById("pdfContainer");
var content = container.innerHTML;
container.innerHTML = content;
}
});
//If I placed Ladda.stopAll(); here, the ladda wouldn't even
//START spinning upon being clicked on.
});
</script>
答案 0 :(得分:2)
我相信这是你的问题
Ladda.bind('button[id=genPDF]');
<强>文档:强>
//点击
自动触发加载动画Ladda.bind(&#39;输入[type = submit]&#39;);
//与上述相同,但在两秒后自动停止
Ladda.bind(&#39;输入[type = submit]&#39;,{timeout:2000});
当它说&#34;在点击&#34;上自动触发加载动画时,它确实就是这样。它加载它,导致它继续运行,因为你从来没有告诉它停止。
答案 1 :(得分:2)
使用此功能
$('#yourladda_btn').click(function(){
var l = Ladda.create(this);
l.start();
$.ajax({
url: 'test.php',
type: "post",
data: {"yourdata":"test"},
success: function(){
}
}).always(
function() {
l.stop();
}
);
});