Ajax路由呼叫控制器名称两次 [英] Ajax Routing Calling Controller Name Twice

查看:85
本文介绍了Ajax路由呼叫控制器名称两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过ajax对我的控制器进行简单的调用. RouteConfig尚未更改并设置为默认值.当我进行ajax调用时,网络"调试工具中要求的网址是:

I am trying to do a simple call to my controller via ajax. The RouteConfig has not been changed and set to the default values. When I make ajax call, the Url that is requested in the "Network" debugging tools is:

'http://localhost:59275/Leaderboard/Leaderboard/GetPosition'

这会导致出现404,因为两次将控制器排行榜添加到了Url中.正确的网址应为

This is causing a 404 because the Controller, Leaderboard, is being added into the Url twice. The correct url should be

'http://localhost:59275/Leaderboard/GetPosition'

我的ajax调用如下:

My ajax call is as follows:

  $.ajax({                
            url: 'Leaderboard/GetPosition',
            type: "GET",
            dataType: 'xml',
            success: function (data) {
                $('#results').html(data);;
            }
        });

和我的控制器如下:

public class LeaderboardController : Controller
    {
        [Webmethod]
         public static DataTable GetPosition()
         {
             // do stuff
         }


    }

推荐答案

如果请求ajax的页面的根URL是"Leaderboard",那么ajax调用上的URL应该仅是"GetPosition"

If the root URL of the page that request the ajax is "Leaderboard" then the url on the ajax call should only "GetPosition"

或者您可以将"/Leaderboard/GetPosition"与前面的"/"一起使用

Or you can use "/Leaderboard/GetPosition" with "/" in front

这篇关于Ajax路由呼叫控制器名称两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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