api.php:
Код: Выделить всё
Route::post('/makeRequest', [App\Http\Controllers\ApiController::class, 'makeRequest'])->name('makeRequest.store');
Route::get('/makeRequest', [App\Http\Controllers\ApiController::class, 'makeRequest'])->name('makeRequest.store');
Код: Выделить всё
@csrf
Код: Выделить всё
function makeRequest(ingredients) {
if (ingredients.length > 0) {
var userInput = ingredients;
var url = `/api/makeRequest?user_input=${encodeURIComponent(
userInput
)}`;
console.log(ingredients);
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ ingredients: ingredients }),
})
.then((response) => response.text())
.then((html) => {
handleApiResponse(html);
})
.catch((error) => {
console.error("Error:", error);
});
} else {
alert("Please add at least one ingredient before submitting.");
}
}

Подробнее здесь: https://stackoverflow.com/questions/783 ... -500-error
Мобильная версия