In one line:- Want to send post data to controller using ajax.
This question is asked many times before.
But i couldn't see the solution to my problem.
My problem is:- "message": "Allowed memory size of 536870912 bytes exhausted (tried to allocate 262148096 bytes)" in the preview tab of network in DEV TOOLS CHROME. I saw this link Allowed Memory size too but no benefit. When only three variables are posted, Why is this problem coming?
My controller code
public function store(Request $request)
{
echo "<pre>";
print_r($request);
echo "</pre>";
}
Jquery Code
$('body').on('click', '.submit_followers', function() {
$('#pactId').val($(this).attr('data-pact'));
$('#userId').val($(this).attr('data-user'));
$('#followersForm').trigger('submit');
});
$(document).ready( function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
});
$('body').on('submit', '#followersForm', function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: "{{route('pacts.addFollowers')}}",
data: {
'_token':$('input[name="_token"]').val(),
'pactId': $('#pactId').val(),
'userId': $('#userId').val()
},
dataType: 'json',
success: function(res) {
console.log(res);
}
});
});
HTML CODE
<div class="col-2 d-flex align-items-center justify-content-center">
<button class="btn btn-outline-violet btn-side-rounded submit_followers" data-user="{{Auth::id()}}" data-pact="{{$pact->id}}" type="button"><i class="fa fa-hand-spock-o"></i> Follow</button>
</div>
{!! Form::open( [ 'method'=>'Post','id'=>'followersForm' ] ) !!}
@csrf
{!!Form::hidden( 'pactId',"",['id'=>'pactId'] )!!}
{!!Form::hidden( 'userId',"",['id'=>'userId'] )!!}
{!! Form::close() !!}
Routes one is resource and another is post
Route::resource("/pactsFollowers","pactsFollowersController");
Route::post('pactsFollowersController/store', 'pactsFollowersController@store')->name('pacts.addFollowers');