With jquery's validation plugin validation plugin, the document says the server needs to return a JSON string, true for valid, "false", undefined, and null for invalid.
Need to verify that the user name has been registered, if it has been registered, return FALSE, if not registered, returns TRUE. The PHP server (Laravel framework) is written like this:
public function verifyName(Request $request) { $username = $request->input('name', ''); $user = User::where('name', $username)->first(); if ($username == $user->name) { return json_encode(false); }else{ return json_encode(true); } }
The front-end JS code is this:
Problem:
When return false, can return normally, want to return true return, appear trying to get the property of Non-object, do not know what reason.
Reply content:
With jquery's validation plugin validation plugin, the document says the server needs to return a JSON string, true for valid, "false", undefined, and null for invalid.
Need to verify that the user name has been registered, if it has been registered, return FALSE, if not registered, returns TRUE. The PHP server (Laravel framework) is written like this:
public function verifyName(Request $request) { $username = $request->input('name', ''); $user = User::where('name', $username)->first(); if ($username == $user->name) { return json_encode(false); }else{ return json_encode(true); } }
The front-end JS code is this:
Problem:
When return false, can return normally, want to return true return, appear trying to get the property of Non-object, do not know what reason.
Does your front-end code forget the post data to the backstage?
data:{
name:function(){ return $("input[name='name']").val();}
}