Reputation: 23587
I am trying to call my Spring MVC controller from a JSP (I-Frame) and getting the following error on the browser
400 Bad Request,The request sent by the client was syntactically incorrect ()
here is my JQuery code to send request to the server
jQuery("#login").live('click', function(e) {
e.preventDefault();
jQuery.ajax({
url: "https://localhost:9002/myApp/springSecurity/login.json",
xhrFields: {
withCredentials: true
},
type: "POST",
crossDomain:true,
data: jQuery("#loginForm").serialize(),
contentType: "json",
success: function(data, status) {
alert(data);
alert(status);
if (data.loggedIn) {
// location.href = getHost() + '${ctx}/users';
//login_pannel
} else {
loginFailed(data);
}
},
error: loginFailed
});
});
This is my controller code
@Controller
@RequestMapping("springSecurity/login.json")
public class SpringSecurityLoginController
{
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public SpringSecurityLoginStatus login(@RequestParam("j_username") final String username,
@RequestParam("j_password") final String password, final HttpServletRequest request, final HttpServletResponse response)
{
LOG.info("Starting login process");
return springSecurityLoginService.login(username, password, request, response);
}
}
While hitting the submit button i am getting no error on the server but while looking at browser console output it showing me the following error
"NetworkError: 400 Bad Request - https://localhost:9002/myApp/springSecurity/login.json"
This is Error information from Mozilla Response header
the request sent by the client was syntactically incorrect ().
I am not sure what causing this behavior. Additionally i am using Spring security to handle authentication and authorization.
Edit
I debugged more and find out that the form values are not being submitted to my controller when i checked the value of j_username
and j_password
in my Controller tey are coming as null.
i even tried request.getParameter("param name");
but still same values are coming as null
Upvotes: 2
Views: 9742
Reputation: 1559
In your jQuery, try changing "contentType" to "dataType" (more information here).
Upvotes: 5