weixin_33735077 2017-04-17 20:03 采纳率: 0%
浏览 49

从任何文件夹调用ajax

I am running an asp.net website with an ajax call. However, I can't get the call to work when in a subfolder.

What I want to have happen is one place to define the ajax call:

function LogOut() {
    $.ajax({
        type: "POST",
        url: "Services/wsvc_Security.asmx/LogOut",
        contentType: "application/json; charset=utf-8",
        async: true,
        success: function (data) { console.log("done"); },
        error: function (request, errorType, errorMessage) { console.log('ajax error - ' + request + '
' + errorMessage); }
    });
}

The problem arises when in the /admin folder ... it can't find my services folder in the root. Yes, I could use /Services/wsvc_Security.asmx/LogOut ... except that on the server I have 2 application paths: /LiveVersion and /TestVersion. I don't want to have to change code when deploying to different environments.

Is there a way to do in javascript what I can do in .Net? meaning: ~/Services/wsvc_Security.asmx/LogOut

Where ~/ gets me the root of the application

  • 写回答

1条回答 默认 最新

  • weixin_33749242 2017-04-17 20:06
    关注

    The correct way to do this would be to have different configs for live and test version. For each of the 2, you could have a root defined differently i.e. in test config, say root = 'live/something' and on test root = 'test/something'. So you'd call the url as
    url: root + "Services/wsvc_Security.asmx/LogOut"

    PS. Bear this in mind that the configs should be seperate for test and live

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度