Spring MVC form submission by ajax don't hitting the given ajax url: ERROR
Recently i experienced a problem regarding posting a form in spring mvc with ajax. i used bootstrap for css design. here i set data by using serialize method.but the form always submitted the url used in form action.
so when i called ajax method it always hits say "enroll.html", not the given ajax url.I tried a lot, but not found any solution. then i found my problem when i clicked submit button. we can design our submit button a lot of ways.
by input type submit,
by input type button
by using bootstrap button
and suppose the ajax method is something like below,
we can write click function for the last one or for the 2nd one in given example.
if we are using the first one, then we not needed to write a click function because when the button clicked it submit the form url given in form tag e.g . "enroll.html"
if we are using the 3rd one and write down a ajax method then it doesn't hit the given ajax url. it always hit the form "action" url e.g enroll.html. so to keep ourselves save, it's better to used 2nd one. That means input type button and for this we can write down any javascript method or ajax call. it hits the url given in ajax method, e.g "ajaxEnroll.html". So everything should worked fine then.
<form:form class="" id="horizontalForm" name="horizontalForm" action="enroll.html">
so when i called ajax method it always hits say "enroll.html", not the given ajax url.I tried a lot, but not found any solution. then i found my problem when i clicked submit button. we can design our submit button a lot of ways.
by input type submit,
<input type="submit" value="Submit" id="submit"/>
by input type button
<input type="button" id="submit">Submit</input>
by using bootstrap button
<button type="button" class="btn btn-default">Submit</button>
and suppose the ajax method is something like below,
$.ajax({
type: 'POST',
dataType: 'json',
url: 'ajaxEnroll.html',
data: $("#horizontalForm").serialize(),
success: function(responseData, textStatus) {
}
});
we can write click function for the last one or for the 2nd one in given example.
if we are using the first one, then we not needed to write a click function because when the button clicked it submit the form url given in form tag e.g . "enroll.html"
if we are using the 3rd one and write down a ajax method then it doesn't hit the given ajax url. it always hit the form "action" url e.g enroll.html. so to keep ourselves save, it's better to used 2nd one. That means input type button and for this we can write down any javascript method or ajax call. it hits the url given in ajax method, e.g "ajaxEnroll.html". So everything should worked fine then.
Comments
Post a Comment