大佬教程收集整理的这篇文章主要介绍了jquery – 我可以为不同的ajax事件控制不同的进度条吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$("#loading img").ajaxStart(function(){ // this progress bar is used by both ajax submission. $(this).show(); }).ajaxStop(function(){ $(this).hide(); }); <div id="loading"> <img src="loading4.gif" border="0" /> </div> $('#countyForm').ajaxForm(options); // Case I: use ajax to submit the form $('form#carSelect').change(function(){ // Case II: use ajax to submit the field $.ajax({ ... } }); });
如何在jQuery中自定义ajax,以便我可以使用不同的进度条进行不同的ajax提交.
对于案例I,我使用image1和案例II我使用image2.
谢谢
而不是使用Ajaxstart和stop,只需首先显示个性化的加载图像,然后直接激活Ajax.当在页面上完成所有ajax时,Ajaxstop将触发.你想要个性化的关注.
ajaxForm插件允许在AJAX触发后的回调函数.使用此选项可删除自定义动画.将click事件处理程序单独绑定到表单的提交按钮以加载该自定义动画.我没有使用过该插件,因此可能有一种更简单的方法.
对于另一种情况,只需加载自定义图像,调用AJAX并成功删除图像.
// Case I -------------------------------- // Bind the event handler to the #countyForm submit button $("#countyForm:submit").click(function() { // Throw in the customized loading animation when the form is submitted. $("#idToShowLoading1").html('<img src="custom1.gif" />'); // .ajaxForm() handles the AJAX and the success. }); // Make use of ajaxForm to handle your form $('#countyForm').ajaxForm(function() { // remove loading img $("#idToShowLoading1").html(''); // Haven't used this plugin,but your options,etc here }); // Case II -------------------------------- $("form#carSelect").change(function() { // First throw in the customized loading animation $("#idToShowLoading2").html('<img src="custom2.gif" />'); // Then make the Ajax call. $.ajax({ url: 'yoururlhere.html/blah.PHP',success: function(data) { // remove loading img or replace it w/ content $("#idToShowLoading2").html(''); // success stuff goes here } }); });
以上是大佬教程为你收集整理的jquery – 我可以为不同的ajax事件控制不同的进度条吗?全部内容,希望文章能够帮你解决jquery – 我可以为不同的ajax事件控制不同的进度条吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。