0

my question is as following:

  1. The project base url is : http://servername/sampelProjectName
  2. The test page url is :http://servername/sampelProjectName/user/home ,in this page I had include a javascript file - datatable.packer.js ,which i had included it using below code:

<script type="text/javascript" th:src="@{/resources/js/datatable.packer.js}"></script>

In the above datatable.packer.js file ,there's a ajax call ,the ajax call url is: "/api/test",like below definition:

var url="/api/test"; 
  1. then when i access the http://servername/sampelProjectName/user/home page ,the ajax call url parsed to : "http://servername/user/home/api/test " ,not the expected url "http://servername/sampelProjectName/api/test", and also if changed the url definition to "api/test" ,then it will parse to url : "http://servername/api/test" ...

any suggestion for this problem ? how to use the url in javascript code ? thanks very much for your help.

1 Answer 1

2

You can define a JS block where you define the URL. not sure how elegant it is but definitely works

<script th:inline="javascript">
    /*<![CDATA[*/
    apiUrl = "http://servername/sampelProjectName/api/test";
   /*]]>*/
</script>

and I think this way your js code will be able to see that variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer ,it can work anyway, also refer this page for the th:inline usage : stackoverflow.com/questions/32596600/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.