I suggest using iframe to load the file instead of ajax,
Sample code for loading a Csv file using struts2 and iframe:
var file = $("#fileUpload").val(); if(file.indexOf(".") != -1 && file.substr(file.indexOf("."))==".csv"){ var iframe = $('<iframe name="uploadIPAddressIFrame" id="uploadIPAddressIFrame" style="display: none" />'); $("body").append(iframe); var form = $('#ipPoolForm'); form.attr("action", "uploadCSVFile.do"); form.attr("target", "uploadIPAddressIFrame"); form.submit(); openDialog(title); $("#uploadIPAddressIFrame").load(function () { response = $("#uploadIPAddressIFrame")[0].contentWindow.document.body.innerHTML; $("#chkIPAddressDiv").html(response); $("iframe#uploadIPAddressIFrame").remove(); });
After loading, if you submit the form, change the purpose of the form:
// Because of using iframe for upload set target value $("#ipPoolForm").attr("target", "");
source share