Unable to understand why this ajax post doesnot work while calling my Play controller
$.ajax({
type: 'POST',
url : '/login',
dataType : 'json',
data: "{username:"+user+",password:"+pass+"}",
success : responseLogin,
error : errorLogin
});
My route.conf
POST /login controllers.UserController.authenticate()
Controller code :
DynamicForm data = form().bindFromRequest();
User user = User.authenticate( data.get("username"),data.get("password"));
But this code works :
$.post('/login',
{'username':$("#txtUsername").val(),'password':$("#txtPassword").val()},
function(data) {
alert(data);
});
});
Why not change your
$.ajaxcall to send data like your$.postcall does? ($.postcalls$.ajaxunder the hood.)Hope this helps.