English 中文(简体)
Browser下载JSON结果,而不是转回文字
原标题:Browser downloads JSON result instead of passing back to script

我已撰写了一份MVC3号申请,其中我使用。 有效载荷。 当用户上载一个档案时,服务器将显示成功/失败以及可能出现错误信息的一个JSON物体上。 一些用户报告说,他们的浏览器要求他们采取行动,如下载档案(假冒/开放),而不是将JSON传到 j。

I m使用分发的上载器,而我的C#控制器将一名JSONResult如此返回。

return JSON(new { success = true }, "application/json");

或者如果情况有误

return JSON(new { success = false, error = exception.Message });

I have been unable to reproduce this, and have gotten reports from users of both IE9 and Chrome. Has anyone had this happen, and what did you do to solve it? Or where should I start troubleshooting?

EDIT: The file uploader will run this on the onComplete event:

function(id, filename, responseJson) {
  if(responseJson.success != true) {
    alert("An error occurred: " + responseJson.error);
    return false;
  }
  return true;
}
最佳回答

突出的问题是,国际电子计算方法没有处理<代码>申请/json内容类型。 将其编为<代码>text/html<>/code>,使其发挥作用,尽管这是很有意义的。

问题回答

引证:

return Json(new { success = true }, JsonRequestBehavior.AllowGet);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签