Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 我可以为不同的ajax事件控制不同的ProgressBar吗?_Jquery - Fatal编程技术网

Jquery 我可以为不同的ajax事件控制不同的ProgressBar吗?

Jquery 我可以为不同的ajax事件控制不同的ProgressBar吗?,jquery,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" bor

我有一个表单,其中有两个地方使用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({
    ...
   }
 });
});
$(“#加载img”).ajaxStart(function(){//两个ajax提交都使用此进度条。
$(this.show();
}).ajaxStop(函数(){
$(this.hide();
});
$(“#countyForm”).ajaxForm(选项);//案例一:使用ajax提交表单
$('form#carSelect').change(function(){//案例二:使用ajax提交字段
$.ajax({
...
}
});
});
如何在jQuery中定制ajax,以便使用不同的progressbar提交不同的ajax

比如,对于案例一,我使用图像1,案例二,我使用图像2

谢谢

不要使用Ajaxstart和stop,只需先显示个性化加载图像,然后直接启动Ajax即可。Ajaxstop在页面上完成所有ajax时触发。你需要个性化的关注

ajaxForm插件允许在AJAX启动后调用函数。使用此选项可以删除自定义动画。分别将单击事件处理程序绑定到表单的“提交”按钮以加载该自定义动画。我还没有用过那个插件,所以可能有一个更简单的方法

对于另一种情况,只需加载自定义图像,调用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         
      }
    });
});
//案例一--------------------------------
//将事件处理程序绑定到#countyForm submit按钮
$(“#countyForm:submit”)。单击(函数(){
//提交表单时插入自定义加载动画。
$(“#idToShowLoading1”).html(“”);
//.ajaxForm()处理AJAX和成功。
});
//使用ajaxForm处理您的表单
$('#countyForm').ajaxForm(函数(){
//卸下装载img
$(“#idToShowLoading1”).html(“”);
//没有使用过这个插件,但是这里有你的选项等等
});
//案例二--------------------------------
$(“表单#carSelect”).change(函数(){
//首先是自定义加载动画
$(“#idToShowLoading2”).html(“”);
//然后进行Ajax调用。
$.ajax({
url:'yoururlhere.html/blah.php',
成功:功能(数据){
//卸下加载img或更换它(带内容)
$(“#idToShowLoading2”).html(“”);
//成功的东西就在这里
}
});
});

你好,彼得,谢谢你的帮助。我们可以添加到代码中的另一个步骤是处理success和error中的结束事件。感谢you@q0987-看看.ajax()文档-。对于处理错误,除了已经存在的
success:
callback函数之外,只需添加一个
error:
callback函数(参考页面上callback functions下的#2)。感谢您的进一步帮助:)