You're using a put request from ajax on a post route.
_method: 'PUT',
Route::post('/ajax/getData/papers', 'HelperController@getPapers');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey,
i searched in the discussions for a while, but i couldn't find any solution for me.
I want to retrieve data from an ajax request but the status is in any way 405 (Method not Allowed)
My Code is:
The Template:
@csrf <div class="form-group {{ $errors->has('product_id') ? ' has-warning' : '' }}">
<label>Produkt</label>
<select name="product_id" id="product_id" class="form-control">
<option>-- Bitte auswählen --</option>
@foreach($products as $product)
<option id="{{$product->id}}" value="{{$product->id}}">{{$product->name}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Hinzufügen</button>
</div>
</form>
The ajax request:
<script>
var product_id = $("#product_id").val();
$('#product_id').change( function() {
$.ajax({
type: 'POST',
data: {
product_id: product_id,
_method: 'PUT',
_token: '{{ csrf_token() }}'
},
url: '/ajax/getData/papers',
cache: false,
success:function(response) {
alert(response);
}
});
});
</script>
The Route:
Route::post('/ajax/getData/papers', 'HelperController@getPapers');
The function in my Controller:
public function getPapers(Request $request) {
$product_id = $request->product_id;
$product = Product::findOrFail($product_id);
return = view('admin.tiles.select', [
'papers' => $product->papers(),
])
->render();
}
I hope you can find any mistakes... i'm at the end of my ideas.
best regards
Thanks for the tips!
My solution is now:
I make a get request and return a blade template like this:
$("#product_id").change(function (e) { e.preventDefault(); var product_id = $("#product_id").val(); var url = window.location.href+'/'+product_id; $('#add_product_form').fadeOut(1700); $('#add_product_form').load(url, function() {
$('#add_product_form').fadeIn(1000);
});
});
</script>
And my Controller is:
public function addProductStep($order_id, $product_id) {
$products = Product::where('published', 1)->get();
$product = Product::findOrFail($product_id);
return view('admin.order.tiles.add_product_form', [
'products' => $products,
'product' => $product,
]);
}
Please or to participate in this conversation.