Javascript 发出完整的ajax调用时,Jquery success未运行
下面您可以看到我正在进行一个简单的ajax调用。但是,在调用成功完成后,我想从页面中删除loader div。问题是success函数没有启动,为什么Javascript 发出完整的ajax调用时,Jquery success未运行,javascript,jquery,Javascript,Jquery,下面您可以看到我正在进行一个简单的ajax调用。但是,在调用成功完成后,我想从页面中删除loader div。问题是success函数没有启动,为什么 utils.get_do stuff = function AJAX_do stuff() { $.getJSON('/url//', function (data) { $.each(data, function (key, val) { // I do s
utils.get_do stuff = function AJAX_do stuff() {
$.getJSON('/url//',
function (data) {
$.each(data, function (key, val) {
// I do stuff with the data here.
});
},
function (success) {
$('#loader').hide();
}
);
};
$.getJSON('/sms/fetch_smartpages/',函数(数据){/
$.getJSON('/sms/fetch_smartpages/',function(data){/这里是一个getJSON
的示例,我认为您必须在完整的处理程序中隐藏$('#loader')
,因此无论请求失败还是成功,$('#loader')
都会隐藏
$.getJSON( "/sms/fetch_smartpages/", function() {
console.log( "success" );
$.each(data, function (key, val) {
//I do stuff with the data here.
});
$('#loader').hide(); //<==== moved from here
})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() {
console.log( "complete" );
$('#loader').hide(); // moved here
});
$.getJSON(“/sms/fetch\u smartpages/”,函数(){
控制台日志(“成功”);
$。每个(数据、函数(键、值){
//我在这里处理数据。
});
$(“#加载程序”).hide();//这里是一个getJSON
的示例,我认为您必须在完整的处理程序中隐藏$(“#加载程序”)
,因此无论请求失败还是成功,$(“#加载程序”)
都会隐藏
$.getJSON( "/sms/fetch_smartpages/", function() {
console.log( "success" );
$.each(data, function (key, val) {
//I do stuff with the data here.
});
$('#loader').hide(); //<==== moved from here
})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() {
console.log( "complete" );
$('#loader').hide(); // moved here
});
$.getJSON(“/sms/fetch\u smartpages/”,函数(){
控制台日志(“成功”);
$。每个(数据、函数(键、值){
//我在这里处理数据。
});
$('#loader').hide();//我怀疑您误解了第二个参数的用途。$.getJSON()
-它通常包含一个JS对象,用于提供将传递到远程服务器的数据
因为您传递了一个函数引用,它被用作“success”回调,第三个参数被忽略
如果确实要使用两个单独的“成功”回调,可以使用.done(f1,f2)
:
请注意,这两个函数都将被传递标准的(response,status,jqXHR)
参数集。我怀疑您误解了第二个参数的用途。$.getJSON()
-它通常包含一个用于提供将传递到远程服务器的数据的JS对象
因为您传递了一个函数引用,它被用作“success”回调,第三个参数被忽略
如果确实要使用两个单独的“成功”回调,可以使用.done(f1,f2)
:
请注意,这两个函数都将通过标准(响应、状态、jqXHR)
一组参数。不接受2个回调参数。请阅读文档。是否尝试使用第一个函数填充数据参数,或使用它处理AJAX结果?不接受2个回调参数。请阅读文档。是否尝试使用第一个函数填充数据参数,或使用它处理AJAX结果?
$.getJSON( "/sms/fetch_smartpages/", function() {
console.log( "success" );
$.each(data, function (key, val) {
//I do stuff with the data here.
});
$('#loader').hide(); //<==== moved from here
})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() {
console.log( "complete" );
$('#loader').hide(); // moved here
});
$.getJSON( "example.json", function() {
console.log( "success" );
})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() { console.log( "complete" ); });
$.getJSON(...).done(function (data) {
$.each(data, function (key, val) {
// I do stuff with the data here.
});
},
function (success) {
$('#loader').hide();
}
);