Ajax发布未命中控制器方法(端点)

时间:2019-05-12 15:20:11

标签: json ajax asp.net-mvc asp.net-ajax

我的Ajax没有达到终点(控制器方法)。我还在控制器上方添加了httpPost,但仍然没有。

我的代码有什么问题?

  $.ajax({
        url: '@Url.Action("RegisterGeolocation", "Account")',
        type: "post",
        contentType: "application/json; charset=utf-8",
        dataType:'json',
        async:true,
        data: { lat: lat,lng:lng },
        success: function (data) {
            console.log('success: ', data);
            }


    });


     [HttpPost]
    public async Task<ActionResult> RegisterGeolocation(int? lat, int?     lng)
    {
        return null;
    }

从IntelliTrace更新

    {
  " name": "Microsoft.ApplicationInsights.Dev.Request",
  "time": "2019-05-12T16:13:21.2978459Z",
   "tags": {
    "ai.internal.sdkVersion": "web: 2.0.0.25000",
   "ai.device.roleInstance": "DESKTOP-6PS7K6Q",
   "ai.operation.name": "POST Account/RegisterGeolocation",
    "ai.operation.id": "lRXiHLdO/XU="
  },
   "data": {
    "baseType": "RequestData",
    "baseData": {
      "ver": 2,
     "id": "lRXiHLdO/XU=",
     "name": "POST Account/RegisterGeolocation",
     "startTime": "2019-05-12T17:13:21.2978459+01:00",
     "duration": "00:00:00.0046229",
     "success": true,
      "responseCode": "401",
      "url": "http://localhost:52381/Account/RegisterGeolocation",
      "httpMethod": "POST",
      "properties": {
       "DeveloperMode": "true"
        }
       }
    }
         } 

这是发生错误时IntelliTrace给我的回馈。但是,在浏览器中表示成功。这有什么问题?

我在Axios内使用Ajax,对您有帮助

已解决

在控制器中,如果我们应用授权批注,则需要指定该方法应以匿名方式访问

0 个答案:

没有答案