I am using Google Oauth using Google Api in Laravel 5.0. I get data about the currently registered user email, id_token, and now I want to send this data to the controller (SigninController) to call our own api and get a response back to the front end (signin.blade.php) via an Ajax request. But my Ajax request is not working. I am attaching codes here.
My Signin.blade.php ajax file looks like (I included the csrf header):
$.ajax({ url: '/signin/oauth', type:"POST", data: data, headers: { 'X-CSRF-Token' : token}, success:function(data){ console.log(data); if(data){ console.log("Success nowwww for ajax expected data!"); // window.location.href = '{{url("/home")}}'; } else{ console.log("Success ajax ! But not expected data!"); // window.location.href = '{{url("/signup")}}'; } },error:function(){ alert("error!! ajax failure !!!!"); } });
My .php routes look like this:
Route::post('/signin/oauth', [ 'uses' => ' SigninController@signinProcessOauth ', 'as' => 'post_signin_oauth', ]);
In my SigninController SigninProcessOauth function, the normal "Request for form" works, but "Request-> ajax ()" may not work. It looks like this:
. . use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; . . public function signinProcessOauth(Request $request) { $getData = $request->ajax(); if ($getData) { $authCode = $request['authCode']; $idToken = $request['idToken']; $userEmail = $request['userEmail'];
Every time I run the code, I get "error! Ajax failure !!!!" answer i.e. ajax failure function called. I can not understand where the problem is? Or is there another way to send data from the view to the controller and return the response to the external interface?
Thank you for reading such a long post patiently. :) :)
source share