0
在这里我有一个AJAX要求,我给了一个url(UpdateURL)
到url param.
在成功的情况下,我要在这里呼吁一个dataTable(called loadGrid()),
我需要同url(UpdateURL)
打电话到loadGrid()
,同时我打了两次相同的url(UpdateURL)
,它会导致重复的请求。 任何人都可以帮助我如何使用url(UpdateURL)
单次和避免重复的请求。对困惑感到抱歉。 这里是我的代码,如何避免重复使用性诉求jQuery的AJAX
$("#UploadButton").click(function(){
$("#idLoading").show();
var UpdateURL="some url";
$.ajax({
type: "post",
url: UpdateURL, // calling first time
dataType: "json",
cache : false,
success: function(response) {
loadGrid(UpdateURL); // calling second time
$("#idLoading").hide();
},
error: function (xhr, status) {
$("#idLoading").show();
timeout_trigger();
}
});
});
function loadGrid(url){
$.getJSON(url,function (output)
{
try
{
var pdlJsonObj = output.aaData;
var tdata = $("#IdDatatble").dataTable({
"aaData": pdlJsonObj,
"bDestroy": true,
"sPaginationType": "full_numbers",
"aaSorting": [],
"fnCreatedRow": function (nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
$(nRow).attr('id', iDisplayIndex);
},
"fnInitComplete": function()
{
$("#IdDatatble tbody tr:eq(0)").find('td').each(function() { });
}
});
}
catch(err)
{
alert(err.message);
}
});
}
这是什么代码在做什么?即应该发生什么? – markpsmith 2015-02-23 10:59:59
为什么不将响应数据保存在全局变量中并使其可用于这两个函数? – sideroxylon 2015-02-23 11:29:14