How to get current page path in jQuery (while doing ajax call)

I am doing Ajax call using jQuery and my URL is like

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

In Demo.aspx page i have a WebMethod, which i wanted to call. While doing jQuery ajax call i am giving the URL as "/DemoWebMethod", where "DemoWebMethod" is the Webmethod present in Demo.aspx page.

But while calling the WebMethod it is calling the URL http://localhost;3327/DummyAps/DemoWebMethod but i want to call http://localhost;3327/DummyAps/Demo.aspx/DemoWebMethod.

I know that changing the URL from "/DemoWebMethod" to "Demo.aspx/DemoWebMethod" will solve the problem but can i do it without writing that (because i have some problem with that).

Can someone please help me?


This should do it, in case you want the entire url:

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

For just the path, try this:

window.location.pathname
链接地址: http://www.djcxy.com/p/70252.html

上一篇: 如何防止Linux上的ksh通过局部变量覆盖全局变量?

下一篇: 如何在jQuery中获取当前页面路径(在做Ajax调用时)