2017-03-02 61 views
0

當前頁面的網址是http://localhost:8080/operator/list.html。在這個頁面中的Ajax應該是http://localhost:8080/operator/somerequest.html 如果ctx = "http://localhost:8080/operator/"然後ajax會工作,但我想用百里香內置符號替換它,所以如何做到這一點?我曾嘗試var ctx = [[${#httpServletRequest.getContextPath()}]]var ctx = [[@{/}]]甚至和這個兩個人,但沒有...如何獲得百里香的url路徑

<script th:inline="javascript"> 
    /*<![CDATA[*/ 
    var ctx = ?; // what thymeleaf annotation 
    /*]]>*/ 
</script> 

我已閱讀this

回答

0

在這種情況下,你真的應該使用相關的網址。假設你的應用程序的上下文是/運營商,該thymeleaf生成的URL應該是:

var url = [[@{/somerequest.html}]]; 

這會給你的/operator/somerequest.html正確的URL。當調用一個jax(例如$.post(url))時,假設localhost:8080。據我所知,thymeleaf沒有提供任何獲得url的「localhost:8080」部分的能力。