Javascript 在jQueryAjax运行时加载gif图像
我试图在ajax调用运行时显示正在加载的图像,但是使用Javascript 在jQueryAjax运行时加载gif图像,javascript,jquery,ajax,html,Javascript,Jquery,Ajax,Html,我试图在ajax调用运行时显示正在加载的图像,但是使用beforeSend属性不会更改结果区域 $.ajax({ url: "/answer_checker.php", global: false, type: "POST", data: ({...clipped...}), cache: false, beforeSend: function() { $('#response').text('Loading...'); }, success: funct
beforeSend
属性不会更改结果区域
$.ajax({
url: "/answer_checker.php",
global: false, type: "POST",
data: ({...clipped...}),
cache: false,
beforeSend: function() {
$('#response').text('Loading...');
},
success: function(html) {
$('#response').html(html);
}
}
提前感谢。您在
缓存:false之后缺少一个逗号。
您还可以使用以下命令:
$('#tblLoading').ajaxStart(function() { $(this).show(); });
$('#tblLoading').ajaxComplete(function() { $(this).hide(); });
我有一个解决方案,它可能不是最好的方法,但它在这种情况下起了作用
$('input').keyup(function () {
$('#response').text('loading...');
$.ajax({
url: "/answer_checker.php",
global: false, type: "POST",
data: ({...clipped...}),
cache: false,
success: function(html) {
$('#response').html(html);
}
});
});
通过在调用ajax函数之前设置resonce内容,它将一直显示加载文本,直到ajax调用更新相同的内容
感谢所有花时间回答问题的人
艾伦我也有类似的问题。为了解决我的问题,我将beforeSend部分中的.text替换为.html,并创建了一个html标记,插入到保存我状态的元素中。success函数没有替换由.text()函数创建的内容,但它确实替换了由.html()函数创建的内容
$.ajax({
url: "/answer_checker.php",
global: false, type: "POST",
data: ({...clipped...}),
cache: false,
beforeSend: function() {
$('#response').html("<img src='/images/loading.gif' />");
},
success: function(html) {
$('#response').html(html);
}
}
$.ajax({
url:“/answer\u checker.php”,
全局:false,键入:“POST”,
数据:({…剪裁…}),
cache:false,
beforeSend:function(){
$('#response').html(“”);
},
成功:函数(html){
$('#response').html(html);
}
}
你的其他选项是什么,例如它是不是偶然的async:false