I'm a beginner in AJAX Jquery. My form will contain an array of values named dualistbox_demo1[] that the user has selected. However, it seems that the ajax function is not storing the values into my database.
My form in blade template:
{{Form::open(array('url' => 'schools/assign',"id"=>"demoform"))}}
<select multiple="multiple" size="10" name="duallistbox_demo1[]">
@foreach($user as $key => $value)
<option value="{{ $value->id}}">{{ $value->FirstName }} {{ $value->LastName }}</option>
@endforeach
</select>
{{ Form::submit('Submit', array('class' => 'btn btn-default btn-block')) }}
{{ Form::close() }}
This is my js script:
<script>
$("#demoform").submit(function() {
$.ajax({
url: 'action',
type: 'POST',
data: ('[name="duallistbox_demo1[]"]').val(),
success : function(data)
{
console.log(data);
}
});
});
</script>
My routes.php:
Route::post('/schools/assign', function(){
if(Request::ajax()){
$AC = new AccessControlEntry();
$AC->UserID = Input::get('duallistbox_demo1');
$AC->save();
}
});
I really can't figure out what/where did I went wrong. Any help is greatly appreciated!