Hi, Just need some help, I have a problem getting the appropriate flow of authentication I want. So right now I have the basic auth that comes with laravel 5.1. In my homepage I have a button that sends and ajax call to an URL, this URL requires authentication. I the user is already logged in there is no problem. But when he is not, the ajax call gets redirected to the login page and then when successfully logged in redirects to a page with my ajax json response echoed. “{ result: ‘Ok’}” What I am expecting is for the page to redirect back to the page from where the Ajax call came from, but can’t seem to make it happen. Thanks in Advance
check the ajax response you get the http code must be 302. which is a redirect. you need to check the http code and redirect yourself using js.
Ajax call is not working in my code, find the below code.
<!DOCTYPE html> <html lang="en"> <header> <meta name="_token" content="{!! csrf_token() !!}"/> </header> <body> <div class="secure">Secure Login form11</div> <form action="login" method="POST" id="myform"> <div class="control-group"> <div class="controls"> <input type="text" name="email" id="" class="form-control span6" placeholder="Email">
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="password" class="form-control span6" name="password" placeholder="Please Enter your Password">
</div>
</div>
<button type="button" class="send-btn" name="login">login</button>
</form> </body> <script type="text/javascript" src="assets/js/jquery.min.js"></script> <script type="text/javascript" src="assets/js/jquery.ui.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $.ajaxSetup({ headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') } }); $('.send-btn').click(function(){ $.ajax({ url: 'login', type: "post", data: {'email':$('input[name=email]').val(), '_token': $('input[name=_token]').val()}, success: function(data){ alert(data); } }); }); }); </script> </html>Throwing: jquery.min.js:6 POST http://localhost/mylaravel/public/login 500 (Internal Server Error)
Ajax call is not working in my code, find the below code.
<!DOCTYPE html> <html lang="en"> <header> <meta name="_token" content="{!! csrf_token() !!}"/> </header> <body> <div class="secure">Secure Login form11</div> <form action="login" method="POST" id="myform"> <div class="control-group"> <div class="controls"> <input type="text" name="email" id="" class="form-control span6" placeholder="Email">
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="password" class="form-control span6" name="password" placeholder="Please Enter your Password">
</div>
</div>
<button type="button" class="send-btn" name="login">login</button>
</form> </body> <script type="text/javascript" src="assets/js/jquery.min.js"></script> <script type="text/javascript" src="assets/js/jquery.ui.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $.ajaxSetup({ headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') } }); $('.send-btn').click(function(){ $.ajax({ url: 'login', type: "post", data: {'email':$('input[name=email]').val(), '_token': $('input[name=_token]').val()}, success: function(data){ alert(data); } }); }); }); </script> </html>Throwing: jquery.min.js:6 POST http://localhost/mylaravel/public/login 500 (Internal Server Error)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community