Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

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



Thank you for your reply.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(