Is It Better To Retrieve Data Through AJAX Or Returning It Alongside View From Controller (Laravel)?
So the scenario is getting data we need from controller and using it in our view. But there are two options, you can have either this line in your "show" method:
And in the 'webpage' you can send an Ajax request to [email protected] and get that data. Or you can get the data from database in [email protected] and then send it alongside view like this:
return view('store', compact('store'));
But which is the more efficient and secure way of doing this?
It really depends on what you're doing, if the data you're requesting and the process you're running takes a lot of time or in a future it would, ajax is the way to go, but if process is short and the requested data from your model is small, then you can request it on the same method that returns your view and send the data to it.
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Passing a JS var from AJAX response to Twig
- → when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
- → Uncaught TypeError Illegal invocation when send FormData to ajax
- → Sent Variable to Controller via Ajax in Blade
- → AJAX folder path issue
- → KNockout JS - Automatic reload of ajax call
- → Upload file with iron-ajax (Google Polymer)
- → Drag and Drop(event) not trigger ajax POST
- → Insert values from FORM to DB using AJAX on october cmd
- → 500 Internal Server Error Ajax Laravel
- → Repeating a function using array of values