1

I am a beginner with spring and am trying to do ajax calls to refresh pages when button is clicked.If i deploy the application with different names in tomcat , will it be possible to pass the application context to the js file from jsp.

The jsp does ajax calls to a jquery methods in a script.js file to be reused. the url in json method will return the result using requestmapping

Contents-scripts.js

    $.getJSON('<app-url>/doSomething/getresult.htm', function(responseJson) {

    $.each(responseJson, function(index, item) {
..
..
..
}
}

I have read about base tag to have the app-url as global , is there any other way to pass app-url to .js files either as parameter or can a EL call like ${pageContext.request.contextPath} be done from .js files

juan
  • 343
  • 3
  • 5
  • 16
  • embed the base path into a var or hidden input and concat the relative path to it in each ajax call. – dandavis Jan 24 '14 at 17:18

1 Answers1

1

1) Passing the context :

Set the context of the page using JSP expression as described here -

How do you get the contextPath from JavaScript, the right way?

2) Refreshing the DOM - This is tricky - Are you refreshing some "part" of HTML or the complete page Do you need to be answered ? This will entirely depend on the way you have implement your page

Community
  • 1
  • 1
user1428716
  • 2,078
  • 2
  • 18
  • 37
  • If i choose to fetch the complete path using document.url will there be any limitations. (eg:- with base i read that inline links with anchor tag will also need full path). – juan Jan 25 '14 at 10:28