1
我有一個遞歸函數generateHtml
這是在表單提交函數中調用。我的問題是success
部分。即使我刪除了成功部分的內容,只是把警報,它不起作用。它也沒有出現任何錯誤。成功的部分不工作.ajax()
function generateHtml(count,total,pars,files) {
if (count == 1) {
f = 'f=';
allfiles = files;
allpars = pars;
}
fn = randomToN(99999999, 0);
f = f + fn + '|';
dat = allpars + "&file=" + allfiles[count] + "&fn=" + fn + '&i=' + count;
alert(dat);
$.ajax({
url: "../../ii/getindreports.php",
type: 'POST',
data: dat,
async:true,
dataType: 'html',
error: function() {
alert('ERROR !!!!');
},
complete: function() {
alert('test');
// -------------------------Success part---------------//
$('#merobar').html($('#merobar').html() + '<br>Report '+ count +' Compiled.');
// if count not equal to total we still have html to process so call the function again
if (count != total) {
count = count + 1;
alert(count);
generateHtml(count, total, 0, 0);
} else {
alert('make pdf now ');
fnpdf = randomToN(99999999, 0);
f = f + '&pdf=' + fnpdf;
$.ajax({
url: "../../ii/makebulkhtmlpdf.php",
type: 'POST',
data: f,
async:true,
dataType: 'html',
success: function() {
//alert('<br>Report Generation Completed');
$('#merobar').html($('#merobar').html() + '<br>Report Generation Completed');
$('#merobar').html($('#merobar').html() + '<br><a href=\"../../temp/temp_'+fnpdf+'.pdf\" target=\"_blank\">Click To Download</a>');
}
});
}//end of else
// -------------------------Success part--------------//
}//end of success
});// end of first .ajax function
return true;
}//end of function
$('#sliderform').submit(function() {
//alert("here");
var files = new Array();
var checked = $("input:checkbox[name=files]:checked").length > 0;
if (!checked) {
alert("Please select at least one Report");
return false;
}
i = 1;
$("input:checkbox[name=files]:checked").each(function() {
//alert($(this).val());
if ($(this).val() != '') {
files[i] = $(this).val();
i = i + 1;
}
});//end of .each
//alert(files);
$('#merobar').html('File Processing ...');
pars = $(this).serialize();
total = $("input:checkbox[name=files]:checked").length;
generateHtml(1,total,pars,files);
});//end of submit function
你介意用正確的縮進格式化你的代碼部分,所以它變得更容易閱讀嗎? –
只是一些樣式指針:使用'var'關鍵字來聲明變量;爲了便於閱讀,請始終保持您的代碼縮進。另外,對於你的問題:'complete()'不是「成功」回調,'success()'是。 –
你好我以前成功了,所以我試着成功。但它似乎在IE中工作。在鉻中工作 – abnab