Jquery Validation Check Username With Remote
I am using the validation plugin and Laravel 4.2. I try to check the username via ajax, but I can't get it work. The username can always be taken, doesn't matter if exists or not.
Solution 1:
It doesn't look like you are sending the data. Try this. Note the post request. Also I believe the dataFilter method should return 'true'
.
Update I just also realized the logic in your php is sending back true if the user exists, therefore the logic in the javascript should be like so:
remote: {
url: "http://"+location.host+"/validation/checkusername",
type: "post",
data: {
username: function () {
return $("input[name='username']").val();
}
},
dataFilter: function (data) {
var json = JSON.parse(data);
if (json.msg == "true") {
return"\"" + "That username is taken" + "\"";
} else {
return'true';
}
}
}
Post a Comment for "Jquery Validation Check Username With Remote"