How to get context path in JQuery?
Suppose you want to get your context path in JS/JQuery on clicking an Button like,
In JSP/HTML:-
In JQuery :-
$('#myButton').click(function() {
console.log(myContextPath);
});
Then you can pass values to JS/JQuery as,
<input type="button" id="myButton" myContextPath="${pageContext.request.contextPath}">
Then in JS/JQuery you can write as,
$('#myButton').click(function() {
var myContextPath = $(this).attr('myContextPath');
console.log(myContextPath);
});
In JSP/HTML:-
<input type="button" id="myButton">
In JQuery :-
$('#myButton').click(function() {
console.log(myContextPath);
});
Then you can pass values to JS/JQuery as,
<input type="button" id="myButton" myContextPath="${pageContext.request.contextPath}">
Then in JS/JQuery you can write as,
$('#myButton').click(function() {
var myContextPath = $(this).attr('myContextPath');
console.log(myContextPath);
});
Comments
Post a Comment