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:-

<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

Popular posts from this blog

How to extend Liferay 6.2 session timeout by AJAX call?