Estoy enviando un dato por ajax con type : 'post', pero me genera error, cuando lo cambio a type : 'get', los datos si son recibidos en success. Este es el codigo.
Ajax
$('.QuestionList-item').on('click', function() {
$('.Question').show();
$('.QuestionList').removeClass('col-12').addClass('col-6');
var param = {
'_token' : $('#token').val(),
'userid': $(this).children('.clientName').val()
};
$.ajax({
url : "{{route('questionDetail')}}",
type : 'post',
dataType: 'json',
data : param,
success : function (data) {
alert('send');
},
error : function() {
alert('error');
}
});
});
Blade
@foreach($questions as $question)
<article class="QuestionList-item row middle">
<figure class="stateIcon">
<svg title="checkmark" viewBox="0 0 32 32" class="svgIcon detailsTitle-checkmarkSvg"><polygon points="30,5.077 26,2 11.5,22.5 4.5,15.5 1,19 12,30"></polygon></svg>
</figure>
<span class="ProductName">{{$question->product->name}}</span>
<input class="clientName" type="text" value="{{$question->user_id}}">
</article>
@endforeach
Ruta
Route::post('preguntas', [
'uses' => 'QuestionController@questionDetail',
'as' => 'questionDetail',
'middleware' => 'VerifyProvider']);
Controlador
function questionDetail(Request $request){
if($request->ajax()){
$user = User::find(1);
return response()->json([$user]);
}
}