Reputation: 320
Platform: spring I'm using ajax call to same function, first for a blur function and then for a click function. But the blur function is working while the click function is not. I changed the name of the function i called and then it's working fine.
Please help me to find a solution. I want to send an ajax call to the function 'isValidPassword' on a blur and and a click function.
On both click and blur i have to do the code below.
if (oldPassword != "") {
$.ajax({
url: 'isValidPassword.html?oldpassword=' + oldPassword,
type: 'GET',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data != "Valid") $("#oldpassworderror").html(data);
return false;
}
});
}
Edit: My problem. I'm trying to do a "change password" in a page. So first i have to check the password entered is same as the saved password. For that i'm using the ajax call. If the password entered is not same as the old password I have to show a error message in tab out(blur) and also the same message should be shown when the user clicks the "save"(click) button. But now the ajax call is working only on blur function and not on click.
Here is the "isValidPassword" function code
@RequestMapping(value = "/isValidPassword", method = RequestMethod.GET)
public @ResponseBody
String isValidPassword(@RequestParam("oldpassword") String oldpassword,
User user, HttpSession session ) throws Exception {
String login = (String)session.getAttribute("userName");
user.setLogin(login);
user.setPassword(oldpassword);
String message = null;
// Check whether old password is valid and
// give a message in front end
if (userService.isValidPassword(user)) {
message = "Valid";
} else {
message = "Incorrect old password";
}
return message;
}
Upvotes: 2
Views: 2263
Reputation: 63
try caching..
if (oldPassword != "") {
$.ajax({
url: 'isValidPassword.html?oldpassword=' + oldPassword,
type: 'GET',
cache: false, // disable caching
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data != "Valid") $("#oldpassworderror").html(data);
return false;
}
});
}
Upvotes: 1
Reputation: 279
To test this code properly, you shall prepare the AJAX call this way:
$.ajax({
url: 'isValidPassword.html?oldpassword=' + oldPassword,
type: 'GET',
contentType: 'application/json; charset=utf-8',
success: function () {
alert('success');
},
error: function () {
alert('error');
}
});
so you can observe if the problem is on client or server side.
Upvotes: 0