What is the best way to use Ajax in Laravel application.
I want to use a simple ajax function in Laravel, I am familiar with jQuery ajax and I read in docs metronic8 does not use jQuery. I want to know, is it okay to include jQuery or metronic8 have anything to perform Ajax?
Replies (3)
You're welcome! Don't hesitate to reach out if you have any further questions or concerns.
Hi Mamta,
The best way to use Ajax in Laravel is by using the Axios library, which is already included in the Laravel package.json file and starterkit/resources/mix/plugins.js. Here's a sample code that you can use:
axios.post("/api/endpoint", {
data: "some data"
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
}); In this example, we are making a POST request to an API endpoint with some data. The then function is called when the request is successful, and the catch function is called when an error occurs. You can modify this code to fit your specific use case.
Thanks