我的代码如下,但我仍然将json结果作为下载文件。我找不到错误在哪里。
我正在使用 ajaxfileupload.js jQuery的1.7.2.min.js Struts2的核心 - 2.3.4.jar struts2的-JSON-插件-2.3.4.jar我的Struts.xml
<action name="hierarchyruleValidate" method="validateRulesFile"
class="com.cotyww.bru.web.action.master.HierarchyUpdateAction">
<result name="success" type="json">
<param name="contentType">text/html</param>
</result>
<result name="error" type="json">
<param name="contentType">text/html</param>
</result>
</action>
我的Ajax脚本:
function validateFile(Url, resultID, buttonId)
{
$('#validatesuccessId').attr('style','display:none');
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
$.ajaxFileUpload({
url:Url,//
secureuri:false,//false
fileElementId:'fileToUpload',//id <input type="file" id="file" name="file" />
dataType: 'json',// json
success: function (data, status) //
{
alert(data.successMessage);//jsonmessage,messagestruts2
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}else
{
alert(data.message);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
);
return false;
}
我的动作类
public String validateFile() throws ApplicationException {
//******* Application logic with uploaded file******
this
.setSuccessMessage("Are you sure you want to upload the file");
this.getHttpResponse().setContentType("text/html");
return Action.SUCCESS;
}