Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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响应时如何加载图像?_Jquery_Ajax - Fatal编程技术网

Jquery 在等待AJAX响应时如何加载图像?

Jquery 在等待AJAX响应时如何加载图像?,jquery,ajax,Jquery,Ajax,我想知道我是否能得到一些建议。我试图在从ajax请求获得响应时使用加载gif。我遇到的问题是,它在发送电子邮件时不会显示gif 我看了几页,试图找到一个解决方案,但似乎没有一个是有效的。这些是我看过的页面:和 我使用了以下代码来尝试实现这一点: $("#loading").bind("ajaxStart", function(){ $(this).show(); }).bind("ajaxStop", function(){ $(this).hide(); }); 这不显示gif,我还尝试了以

我想知道我是否能得到一些建议。我试图在从ajax请求获得响应时使用加载gif。我遇到的问题是,它在发送电子邮件时不会显示gif

我看了几页,试图找到一个解决方案,但似乎没有一个是有效的。这些是我看过的页面:和

我使用了以下代码来尝试实现这一点:

$("#loading").bind("ajaxStart", function(){
$(this).show();
}).bind("ajaxStop", function(){
$(this).hide();
});
这不显示gif,我还尝试了以下方法:

$.ajax({
 type: "POST",
 url: "contact1.php",
 data: dataString,
 beforeSend: loadStart,
 complete: loadStop,
 success: function() {
  $('#form').html("<div id='msg'></div>");
  $('#msg').html("Thank you for your email. I will respond within 24 hours. Please reload the page to send another email.")
 },
 error: function() {
  $('#form').html("<div id='msg'></div>");
  $('#msg').html("Please accept my apologies. I've been unable to send your email. Reload the page to try again.")
 }
}); 
return false;
});
function loadStart() {
  $('#loading').show();
}
function loadStop() {
  $('#loading').hide();
}
$.ajax({
类型:“POST”,
url:“contact1.php”,
数据:dataString,
发送前:加载开始,
完成:加载停止,
成功:函数(){
$('#form').html(“”);
$('#msg').html(“感谢您的电子邮件。我将在24小时内回复。请重新加载页面以发送另一封电子邮件。”)
},
错误:函数(){
$('#form').html(“”);
$('#msg').html(“请接受我的道歉。我无法发送您的电子邮件。请重新加载页面以重试。”)
}
}); 
返回false;
});
函数loadStart(){
$(“#加载”).show();
}
函数loadStop(){
$(“#加载”).hide();
}
我还尝试将$(“#load”).show()放在ajax请求之前,并在success和error函数中unsing.hide()。我还是什么也没看到


提前感谢

实际上,您需要通过侦听ajaxStart和Stop事件并将其绑定到
文档来实现这一点:

$(document).ready(function () {
    $(document).ajaxStart(function () {
        $("#loading").show();
    }).ajaxStop(function () {
        $("#loading").hide();
    });
});
$(文档).ajaxStart(函数(){
$(“#加载”).show();
}).ajaxStop(函数(){
$(“#加载”).hide();
});
$('.btn')。单击(函数(){
$('.text').text('');
$.ajax({
键入:“获取”,
数据类型:“jsonp”,
url:“https://api.meetup.com/2/cities",
成功:功能(数据){
$('.text').text('找到的集合:'+data.results.length);
}
});
});
#加载{显示:无;}

点击我!

加载。。。
这会等待很重的内容被加载吗?这对html有什么影响?它在哪里添加了“#加载”?看起来像css id,但指向哪个div?或者它是否添加了一个空div,比如:
@MichaelRogers这个想法是在页面上有一个元素,带有
#loading
id,以便在Ajax调用开始和停止时分别显示和隐藏它。查看代码片段,其中有一个id为的div。在这个非常棒的答案中,默认情况下它是隐藏的。没有按钮如何加载ajax加载程序。我有三个下拉列表,第一个和第二个用户输入,第三个基于前两个下拉列表的自动响应,这里我如何加载ajax加载程序@帕拉ѕѕѕѕѕ能不能请你为它创建一个在线演示(),这样我就可以查看它并为你提供一些关于它的信息。谢谢