url: window.location.href,
Use the route here, you don't need window.location.href, Use that if editing, and after complete you are redirecting somewhere.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using jQuery Ajax to update data, so i use window.location.href in 'url' parameter to get the route, and the method i set to patch, which is the same as my route file, but, seems jQuery is sending the wrong url, i don't understand why.
THE CURRENT URL:
http://localhost:8000/clients/1/edit
THE ROUTE FILE:
Route::prefix('clients')->group(function() {
Route::name('clients.')->group(function() {
.
.
.
Route::patch('/{client}/edit', 'ClientsController@update')->name('update');
});
}
MY JAVASCRIPT CODE:
$("#btn-update").on('click', function(e) {
e.preventDefault();
// here i get the data object i need
let data = getData($("input").is("[name=cpf]"), false);
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: 'PATCH',
url: window.location.href,
data: data,
success: function(data) {
console.log(data.responseText);
},
error: function(data) {
console.log(data.responseText);
}
});
But, here is the error i get:
PATCH http://localhost:8000/clients/1 405 (Method Not Allowed)
It seems that Query is not sending the complete URL, it should send http://localhost:8000/clients/1/edit (the CURRENT URL), but just sends http://localhost:8000/clients/1
So, why this bug is happening? I already try to check the url using console.log(window.location.href) and it returns the right URL, but when i sendo via ajax jQuery parameter its sends wrong (without the 'edit' at the end), why?
Please or to participate in this conversation.