When i do a Ajax request , for the url mentioned below , it is concatenating the url value which i have mentioned along with the pathname of the URL of the page.
JSP:
<form:form modelAttribute="createtask" id="create-task-form" name="create-task-form">
<div class="task">
<form:input path="taskName" placeholder="enter task"/>
<c:url value="/createtask/${todo.todoId }" var="createtaskUrl" />
<a id="create-task" href="${createtaskUrl }"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
</div>
</form:form>
Jquery Ajax call:
$("a#create-task").click(function(event){
event.preventDefault();
var todoid = this.href.substring(this.href.lastIndexOf("/")+1,this.href.length);
var createTaskForm = $("#create-task-form").serialize();
$.ajax({
type : "POST",
url : "createtask/"+todoid,
data : createTaskForm,
dataType : "text",
success : function(data){
console.log("Created Task successfully..");
$("section#taskviewer").html(data);
}
});
});
I know it concatenates with the context path of the application. For example if my application context path is localhost:8080/SpringMVCPractice/ and the page in which I do the Ajax request is
http://localhost:8080/SpringMVCPractice/viewTodo/110
and when I do a ajax request by clicking the anchor tag, the url it takes is
http://localhost:8080/SpringMVCPractice/viewTodo/createtask/110
Why it is not taking localhost:8080/SpringMVCPractice/createtask/110
?
Any suggestion? I am relatively new to Ajax.