#Call a route without reloading the current page

7 messages · Page 1 of 1 (latest)

low nexus
#

I have a page that uses google map api integration with a key and all. The thing is each time I load/reload the page I use 1 credit with the API. I need to insert things in the DB with a button on the page, but if I call a route with this button, I either exit the current page with the route or in my controller I redirect back or directly to the previous route, but in each of these cases I use an extra credit. Is there a solution ?

pulsar mica
#

If you use an ajax request, you won't exit the current page.

#

Which frontend stack are you using?

low nexus
pulsar mica
#

That's fine. Then you can add an event listener in JavaScript that uses axios to submit the data when the button is pressed.

low nexus
#

I submit the data by calling the route in JS right ? What I mean is do I create the route, controller in php and with JS I call the route or I use JS and Ajax to insert in the db so without controller, route and all ?

pulsar mica
#

If you have a normal store() route, just call that route from JavaScript with the data that it needs.