首页 新闻 会员 周边

ajaxFileUpload 上传文件 chrome中出现SyntaxError:unexpected token <,在IE下直接下载保存返回的Json

0
悬赏园豆:10 [已关闭问题] 关闭于 2011-12-16 20:16

HTML:

<input type="file" id="projectFile" name="projectFile"/>



javascript:

$(function () {
$('#projectFile').live('change', function () {
$.ajaxFileUpload({
url: '/Management/SaveProjrctFile/', //需要链接到服务器地址
secureuri: false,
fileElementId:'projectFile', //文件选择框的id属性
dataType:'json', //服务器返回的格式,可以是json
success: function (data, status) //相当于java中try语句块的用法
{

alert("OK" + data.name + "-" + data.path);

},
error: function (data, status, e) //相当于java中catch语句块的用法
{
alert( e );
}
});
});

});

Action:

 public ActionResult SaveProjrctFile(HttpPostedFileBase projectFile)
{
HttpPostedFileBase file = projectFile;
if (file != null)
{
try
{
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Content\\UploadFiles";
string fileName = Path.GetFileName(file.FileName);
string savePath = string.Format(@"{0}\{1}", filePath, fileName);
file.SaveAs(savePath);

return Json(new { name = fileName });
}
catch (Exception ex)
{
return Json(new { error = ex });
}
}
else
{
return Json(new { error = "未选择文件"});
}
}


检查了没出现错误的“<”!

SatanRabbit的主页 SatanRabbit | 初学一级 | 园豆:114
提问于:2011-11-22 12:13
< >
分享
所有回答(2)
0

实验证明,直接返回Json不行,只能返回Content,Json形式的字符串

SatanRabbit | 园豆:114 (初学一级) | 2011-12-16 20:16
0

我出现了 Uncaught SyntaxError: Unexpected end of input  

伍德兄--龙龙 | 园豆:172 (初学一级) | 2013-03-07 17:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册