使用ajax方式提交表单
[code="html"]
function simpleAjaxForm(formName, check){
$("#" + formName).ajaxForm({
dataType: "json",
beforeSubmit: function(){
var msg = check ? validator(check) : null;
if(msg) dialogBox(msg);
return msg ? false : true;
},
success: function(ret){
ajaxReturn(ret);
}
});
}
//ajax返回函数
function ajaxReturn(ret) {
if(ret.msg) $.prompt("系统提示", ret.msg, {submit: function(clicked){
if(ret.url) location.href = ret.url;
return true;
}});
else if(ret.url) location.href = ret.url;
}
[/code]
后台返回一个json格式的数据,{"msg":"发送成功","url":"order_apply_list.html"}
正常的话,应该是弹出一个发送成功的对话框,然后点击确定,跳转到order_apply_list.html页面才对
但是老是提示我下载保存
PS:前台表单,包含了附件上传
不清楚,你可以暂时先使用下面代码。直接使用response,不用@RsponseBody注解
[code="java"]response.setContentType("text/html")
response.getWriter().writer("{msg:''}");[/code]
附件上传采用的是iframe 作为ajax提交。iframe在识别 text/json头文件时会当做文件进行下载。可以吧头文件去了。
[code="java"]response.setContentType("text/json; charset=UTF-8");[/code]
是application/json
[code="java"]response.setContentType("application/json;charset=utf-8");[/code]
都一样吧他去了,或者改成
response.setContentType("text/html")
吧dataType: "json", 去了。
function ajaxReturn(ret) {
ret = jQuery.parseJSON(ret); //解析json字符串
}
ret = jQuery.parseJSON(ret); 查看是否是这句出现问题。
jquery对json解析有很严格的限制
需要这种格式
[code="java"]response.getWriter().write("{\"msg\":\"发送成功\"}");[/code]
response.setContentType("application/json;charset=utf-8");
这个是正确的
标准写application/json,文件下载是浏览器的问题,参看
http://connect.microsoft.com/IE/feedback/details/793307/text-json-mimetype