I'm trying to set up ajax for laravel, but it won't work. I have controller for check validation and update from database. javascript which blocks the submit form do not work and page is refresh.
do not work means: alert('SUBMIT');
into submit form not work and alert me without any error and warning.
i test alert('SUBMIT');
but that does not work. but alert('ACTION');
correct and alert me.
my included correct JS:
<head>
<title>Alachiq</title>
<meta charset='UTF-8' />
{{HTML::script('js/jquery-1.9.1.min.js')}}
</head>
jQuery:
<script type="text/javascript">
$(document).ready(function() {
alert('ACTION');//
$('#submit').click(function(){
alert('SUBMIT');
name = $('#name').val();
family = $('#family').val();
email = $('#email').val();
currPassword = $('#currPassword').val();
password = $('#password').val();
password_confirmation = $('#password_confirmation').val();
$.post("{{ URL::route('admin.profile.update') }}",
{
name : name,
family : family,
email : email,
currPassword : currPassword,
password : password,
password_confirmation : password_confirmation
},
function()
{
alert('sss');
},'json');
});
});
</script>
my sample of form:
{{ Form::model($profile, array('route' => array('admin.profile.update', $profile->id), 'method' => 'PUT')) }}
...
{{ Form::close() }}
my simple controller
public function update($id)
{
if ( Request::ajax() ){
return Response::json(array(
'errors'=>'ddddd'
));
}
}
UPDATE: my route:
Route::group(array('before' => 'auth'), function()
{
Route::get ('admin/contents', array('as'=>'contents', function(){
return View::make('back_end.layouts.contents');
}));
Route::resource ('admin/profile' , 'ProfileController' , array('as'=>'profile', 'before'=>'csrf'));
Route::get('admin/createNewContents' ,array('as'=>'createNew', function(){
return View::make('back_end.layouts.createNewContents');
}));
});