asp.net - 如何在 jQuery 中获取当前页面路径(在进行 ajax 调用时)

标签 asp.net jquery ajax

我正在使用 jQuery 进行 Ajax 调用,我的 URL 类似于

http://localhost;3327/DummyAps/Demo.aspx

在 Demo.aspx 页面中,我有一个 WebMethod,我想调用它。在执行 jQuery ajax 调用时,我将 URL 指定为“/DemoWebMethod”,其中“DemoWebMethod”是 Demo.aspx 页面中存在的 Webmethod。

但是在调用 WebMethod 时,它正在调用 URL http://localhost;3327/DummyAps/DemoWebMethod但我想打电话 http://localhost;3327/DummyAps/Demo.aspx/DemoWebMethod .

我知道将 URL 从“/DemoWebMethod”更改为“Demo.aspx/DemoWebMethod”可以解决问题,但是我可以不写它来做到这一点吗(因为我对此有一些问题)。

有人可以帮我吗?

最佳答案

如果您想要完整的网址,这应该可以做到:

window.location.href.split("#")[0]

如果只是路径,请尝试以下操作:

window.location.pathname

关于asp.net - 如何在 jQuery 中获取当前页面路径(在进行 ajax 调用时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3511677/

相关文章:

php - jQuery AJAX : Clarification on How to Pass Variable into AJAX GET Request

javascript - jquery 插件设置 this 的值

javascript - 当用户向下滚动一定量(像素)时执行jquery代码

python - 使用 AJAX 通过用户输入从数据库中检索记录

c# - 无法将属性或索引器 'System.DateTime.TimeOfDay' 分配给 — 它是只读的

javascript - 用鼠标在图像上拖动文本框

javascript - Ajax - 访问 protected 资源

javascript - 使应用程序可以通过两个域访问同源 AJAX 请求

c# - 使用 C# 和 InsertParameters (ASP.NET) 没有时间的日期

jquery - ASP.NET MVC 4 - 客户端验证不起作用