mardi 25 août 2015

Ajax Post not Working in laravel 5.1

i am trying to post data using ajax in laravel but it seems to be not working .i have followed following is my code

login.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="csrf_token" content="{{ csrf_token() }}" />

<link rel="stylesheet" href="http://ift.tt/1K1B2rp">
<link rel="stylesheet" href="http://ift.tt/1QMqYrP">
<script src="http://ift.tt/1LdO4RA"></script>
<script src="http://ift.tt/1InYcE4"></script> 
<style type="text/css">

</style>
<script type="text/javascript">
$(document).ready(function(){
  $('.send-btn').click(function(){   
  console.log($('input[name=email]').val());
    $.ajax({
      url: 'login',
      type: "post",
      data: {'email':$('input[name=email]').val(), '_token': $('input[name=_token]').val()},
      success: function(data){
      console.log($('input[name=email]').val());
        alert(data);
      }
    });      
  }); 


});
</script>
</head>
<body>
<div class="secure">Secure Login form</div>
{!! Form::open(array('url'=>'account/login','method'=>'POST', 'id'=>'myform')) !!}
<div class="control-group">
  <div class="controls">
     {!! Form::text('email','',array('id'=>'','class'=>'form-control span6','placeholder' => 'Email')) !!}
  </div>
</div>
<div class="control-group">
  <div class="controls">

  </div>
</div>
{!! Form::button('Login', array('class'=>'send-btn')) !!}
{!! Form::close() !!}
</body>
</html>                                     

and route.php

Route::get('account/login', function() {
  return View::make('login');
});
Route::post('account/login', 'AccountController@login');

and in controller

 public function login() {
    // Getting all post data
    if(!Request::ajax()) {
      $data = Input::all();
      print_r($data);
    }

    }

whenever i try to submit form not working.i tried using alert in onclick jquery but it shows alert message.can any one tell why its not working ?.

note :this question already asked but not found any answer useful for me

Laravel 5.1 ajax not working?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1U40d3E
via IFTTT

Aucun commentaire:

Enregistrer un commentaire