浏览器在Azure Web应用程序上显示来自ActionResult的json响应,但不在localhost上显示 [英] Browser display json response from ActionResult on Azure Web app, but not on localhost

查看:119
本文介绍了浏览器在Azure Web应用程序上显示来自ActionResult的json响应,但不在localhost上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据发布到Action,作为结果获取json数据,然后以javascript处理结果.

I am posting data to an Action, get json data as a result, and then, process the result in javascript.

它在开发服务器上运行良好,但是当我在Azure WebApp上发布它时,当我发布数据时,它会在屏幕上显示json.

It's work well on dev server, but when i publish it on Azure WebApp, when I post my data, it display the json on the screen.

我的表格开始发布数据:

The begining of my Form to post data :

@using (Ajax.BeginForm("UpdateAccount", "Loging",
new AjaxOptions
{
    HttpMethod = "POST",
    OnSuccess = "processAccountUpdateResult"
}))
{

注意: processAccountUpdateResult 是用于处理json结果的javascript函数.

Note: processAccountUpdateResult is the javascript function which process the json result.

这是我的动作:

[HttpPost]
public ActionResult UpdateAccount(string newName)
{
    return Json(new { result = "ok" }, "text/html", JsonRequestBehavior.AllowGet);
}

注意:我在

Note : I added the "text/html" mime type after I read this But no luck. I tried to add the json mimetype in the web.config, but still no luck :

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json"/>
    </staticContent>
  </system.webServer>
</configuration>

谢谢

推荐答案

要使其正常运行,我们需要将其添加到web.config中:

To make it working, we need to add this to the web.config :

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

这篇关于浏览器在Azure Web应用程序上显示来自ActionResult的json响应,但不在localhost上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆