加载页面时,我正在执行AJAX调用,如图所示
<script>
$(function() {
var ajaxQuery = fecthDocumentData("","");
ajaxQuery.done(function() {
});
});
</script>
function fecthDocumentData(document_id, btnname)
{
$.ajax({
type: 'GET',
url: url + '/OMS/admin/document?document_row=' + document_id + '&btnName=' + btnname,
jsonpCallback: 'jsonCallback',
dataType: 'jsonp',
jsonp: false,
success: function(response) {
var res = response;
},
error: function(e) {}
});
}
我的问题是在这种情况下我怎么知道 Ajax 调用已经完成?
我尝试使用
ajaxQuery.done(function() {
alert('Ajax call completed callback called ');
});
但是我收到错误,因为无法读取此行未定义的属性ajaxQuery.done(function() {
返回$.ajax()
调用的承诺
function fecthDocumentData(document_id, btnname) {
return $.ajax({
type: 'GET',
url: url + '/OMS/admin/document?document_row=' + document_id + '&btnName=' + btnname,
jsonpCallback: 'jsonCallback',
dataType: 'jsonp',
jsonp: false,
success: function(response) {
var res = response;
},
error: function(e) {}
});
}
查看成功函数中的响应...尝试向 0r 控制台发出响应数据警报。.
即,
function fecthDocumentData(document_id, btnname)
{
$.ajax({
type: 'GET',
url: url + '/OMS/admin/document?document_row=' + document_id + '&btnName=' + btnname,
jsonpCallback: 'jsonCallback',
dataType: 'jsonp',
jsonp: false,
success: function(response) {
var res = response;
alert(res); //check out the value and if you get any value here .. and to what ever stuff you want here
},
error: function(e) {}
});
}
没有必要使用 .done 函数...
ajaxQuery.done(function() {
});
您只能在成功函数中执行此操作