你好,我需要知道 导出 excel文件从服务器端发送到浏览器的时间,在这期间要显示进度条。 利用AJAX方式导出excel 不知是否可行,代码如下:
function exportFileWithAjax(serverUrl, formData, successCallback, errorCallback) {
formData = htmlSpecialCharsEntityEncode(formData);
$.ajax({
url: serverUrl, //Server script to process data
type: 'POST',
success: function completeHandler(data, textStatus, jqXHR) {
alert("导出成功");
},
error: function errorHandler(jqXHR, textStatus, errorThrown) {
alert("导出失败");
}
});
}
替换你们例子中的
function exportFile(serverUrl, content) {
var formInnerHtml = '<input type="hidden" name="type" value="application/json" />';
formInnerHtml += '<input type="hidden" name="data" value="' + htmlSpecialCharsEntityEncode(content) + '" />';
var $iframe = $("<iframe style='display: none' src='about:blank'></iframe>").appendTo("body");
$iframe.ready(function () {
var formDoc = getiframeDocument($iframe);
formDoc.write("<html><head></head><body><form method='Post' action='" + serverUrl + "'>" + formInnerHtml + "</form>dummy windows for postback</body></html>");
var $form = $(formDoc).find('form');
$form.submit();
});
}
,但是返回500错误,
错误信息如下:
{
"Message":"An error has occurred.",
"ExceptionMessage":"Value cannot be null.\r\nParameter name: content",
"ExceptionType":"System.ArgumentNullException",
"StackTrace":" at System.Net.Http.StringContent..ctor(String content, Encoding encoding, String mediaType)\r\n at GrapeCity.ExcelIO.Controllers.ExportController.SpreadParamBinding.<ExecuteBindingAsync>d__6.MoveNext()"
}
。请问如何解决。谢谢 |
|