your first mistake return without /
return view('pages.index');
it's very hard to read your code
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello! i am new to laravel and i have a issue, i want to sent data to controller from js(client side) and i have write the ajax code and it's working but my controller is not working. here is my route.php:
Route::get('/test', 'ListingsController@viewTest');
Route::post('/test', 'ListingsController@doTest');
the 'hellowolrd' in the console is appearing and here is my view:
@extends('layouts.app')
@section('content')
{{Form::text('test', '', [ 'id' => 'test'])}}
{{Form::submit('submit', ['class' => 'btn btn-primary', 'onclick' => 'getData()'])}}
@endsection
<script>
function getData(){
var value = document.getElementById('test').value;
console.log('----------------',value)
$.ajax({
type:'POST',
url:'/test',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {value},
success:function(){
console.log('hello world');
}
})
}
</script>
but the controller is not running and here is my controller:
public function doTest(Request $request){
print($request->value);
return view('/pages.index');
}
Please or to participate in this conversation.