简体   繁体   English

jQuery ajax调用强制响应小写

[英]jquery ajax call is forcing response to lowercase

Hi I am making a AJAX Call from my .net Application in below manner 嗨,我正在以下列方式从.net应用程序进行AJAX呼叫

$.ajax({
       type: 'POST',
       url: '@Url.Action("GetRouteUsingJobId", "Home")',
       contentType: 'application/json; charset=utf-8',
       dataType: "json",
       data: JSON.stringify({ "jobid": jobid }),
         success: function (result) {
           var response = result.result;
           var RouteArray = response.eSRIRouteResponse.features;
           //RouteArray = response.eSRIRouteResponse.Features; //ERROR
         },
         error: function (request, status, error) {
           alert('Error: Unable To Get Route details.');
         }
});

When I am trying to access Features from eSRIRouteResponse like below it is giving error 当我尝试从eSRIRouteResponse访问功能(如下所示)时,出现错误

var RouteArray = response.eSRIRouteResponse.Features; //ERROR

But this working 但是这个工作

var RouteArray = response.eSRIRouteResponse.features;

From my MVC Controller I am returning like below 从我的MVC控制器中,我将返回如下内容

ESRIRouteResponse eSRIRouteResponse=Some Value;
return Json(new { eSRIRouteResponse },JsonRequestBehavior.AllowGet);

And my model class contains eSRIRouteResponse like below 我的模型类包含eSRIRouteResponse,如下所示

public class ESRIRouteResponse
{
    public Features Features{ get; set; }
}

I am using JQUERY 3.2.1 我正在使用JQUERY 3.2.1

What is the issue,How to rectify ? 有什么问题,如何纠正?

RouteArray = response.eSRIRouteResponse.features;

you are basically accessing the other attributes inside the response. 您基本上是在访问响应中的其他属性。 The response contains the data that has been sent back from the action. 响应包含已从操作发送回的数据。 You cannot directly access your model properties in the response. 您不能直接在响应中访问模型属性。

So, 所以,

RouteArray = response.eSRIRouteResponse.Features;

the above won't work. 以上不起作用。

Would you try to remove dataType: "json" and parse the response manually. 您是否尝试删除dataType: "json"并手动解析响应。

     success: function (result) {
       var response = JSON.parse(result);
       RouteArray = response.eSRIRouteResponse.Features;
     },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM