Relative URL in JQuery Post Call

前端 未结 7 1853
终归单人心
终归单人心 2021-01-30 17:22

I have the following situation.

I developed my first MVC Asp.Net application. it runs on my server at the following adress

http://localhost:59441/
         


        
7条回答
  •  暖寄归人
    2021-01-30 17:58

    As far as I know there is no other way around this. Unless you are willing to user relative URL's i.e:

    $.ajax({
            type: "POST",
            url: "./CeduleGlobale/UpdateCheckBox", ...
    

    But that can get messy for various reasons when you refactor code. Alternatively prepend the URL which is globally defined and therefore you then only need to change it in once place before going to production.

    i.e.

    //Globally defined serverRoot
    serverRoot = "http://someaddress/somevirtualdirectory";
    
    $.ajax({
            type: "POST",
            url: serverRoot + "/CeduleGlobale/UpdateCheckBox", ...
    

    That way if you don't need it you can just set serverRoot = ''; and all will be back to how it is now.

提交回复
热议问题