简体   繁体   中英

jquery ajax call is forcing response to lowercase

Hi I am making a AJAX Call from my .net Application in below manner

$.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

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

But this working

var RouteArray = response.eSRIRouteResponse.features;

From my MVC Controller I am returning like below

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

And my model class contains eSRIRouteResponse like below

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

I am using 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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