Java 用于ajaxfile上载的struts2 json结果类型
我有如下代码,但我仍然得到json结果作为下载文件。我找不到错误在哪里 我正在使用 ajaxfileupload.js jquery-1.7.2.min.js struts2-core-2.3.4.jar struts2-json-plugin-2.3.4.jar 我的Struts.xmlJava 用于ajaxfile上载的struts2 json结果类型,java,javascript,jquery,json,struts2,Java,Javascript,Jquery,Json,Struts2,我有如下代码,但我仍然得到json结果作为下载文件。我找不到错误在哪里 我正在使用 ajaxfileupload.js jquery-1.7.2.min.js struts2-core-2.3.4.jar struts2-json-plugin-2.3.4.jar 我的Struts.xml <action name="hierarchyruleValidate" method="validateRulesFile" class="com.cotyww.bru.web
<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>
在validateFile方法或struts.xml中尝试将application/json作为您的内容类型?很好。穆萨谢谢。成功了。
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;
}