I want the user to register using ajax and when everything goes right I want to return JSON response {'success', 'thank you'} now in order to do that in register controller i overwrite the register method as follow:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
if($request->ajax()){
return response()->json(["success", "thank you"], '200');
}
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
but in Javascript/JQuery I get the following:
VM2666:1 Uncaught SyntaxError: Unexpected token s in JSON at position 0
at JSON.parse (<anonymous>)
at Object.success ((index):2003)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at z (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
success @ (index):2003
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
z @ jquery.min.js:4
(anonymous) @ jquery.min.js:4
load (async)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
(anonymous) @ (index):1997
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
what is wrong? how to fix it please?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire