jQuery Ajax: Reference MVC controller url from App root

前端 未结 2 1059
粉色の甜心
粉色の甜心 2021-01-05 06:54

I have an ASP.NET MVC web application running from http://localhost/myappname. From jQuery, I make jQuery $.ajax() calls to return partial views based on some

2条回答
  •  逝去的感伤
    2021-01-05 07:33

    I was able to accomplish this with straight JavaScript using window.location.pathname. See the following example:

    function loadMyPartialView() {
        $.ajax({
          type: 'GET',
          url: window.location.pathname + 'Home/GetNavigationTreePV/',
          success: function (data) { onSuccess(data); },
          error: function (errorData) { onError(errorData); }
        });
        return true;
    }
    

提交回复
热议问题