How to get relative path in Javascript?

前端 未结 6 722
野的像风
野的像风 2020-12-09 18:47

In my ASP.net web project, I\'ve written the following Javascript code in a .js file:

function getDeviceTypes() {
    var deviceTypes;
    $.ajax({
        a         


        
6条回答
  •  醉话见心
    2020-12-09 19:05

    Create an app root variable...

    var root = location.protocol + "//" + location.host;
    

    And use an absolute URI (instead of relative) when you are making AJAX requests...

    url: root + "/Controls/ModelSelectorWebMethods.aspx/getDeviceTypes"
    

提交回复
热议问题