2010-08-18 39 views
1

我做使用jQuery Ajax調用和我的網址是像如何獲得當前頁面的路徑的jQuery(同時做Ajax調用)

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」將解決該問題,但是我可以不用編寫它(因爲我有一些問題)。

有人可以幫我嗎?

+0

的可能重複( http://stackoverflow.com/questions/1034621/get-current-url-with-javascript) – Lazarus 2010-08-18 11:51:46

+0

可能的重複http://stackoverflow.com/questions/406192/how-to-get-the-current-url-也在jQuery中 – 2010-08-18 11:53:40

+0

但是,如果我的網址是像Demo.aspx#divNote或類似的東西,那麼它不工作。 在這種情況下,我必須獲取整個網址並找出確切的網頁名稱。 – 2010-08-18 11:53:46

回答

4

這應該這樣做,如果你想整個網址:

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

對於人的路,試試這個:[?獲取使用javascript當前URL]

window.location.pathname 
+0

這也可能工作,如果你傳遞一個get變量: window.location.href.split(「?」)[0] – 2012-10-23 09:50:24

相關問題