Can Someone Editing my ajax code - ajax

when I am using ajax in laravel to post if the button is clicked very fast and to much it will cause some of the posts to finish updating the database faster than others, which cuases a counter field in my database to have wrong data, I am using async:false, my question is can a user edit my ajax in there browser and send the ajax code with out async:false?

maybe it can be done, use post request so it can't be injected because it checks CSRF session.

Related

How to code in Laravel so that the requests are executed without refreshing the page?

In Laravel when we using forms to store or delete a resource, the page is refreshed. What is the best technology to avoid refreshing the page while the request is being processed? AJAX, Vue.js, etc?
There are two main ways to handle http requests: synchronously and asynchronously.
Laravel is a PHP framework and therefore uses... PHP, which is a synchronous language. This implies a page refresh for every requests you make. The point is, every PHP framework have this behavior, this is the way PHP works.
So let's answer your question: indeed, you need an asynchronous technology to make a request to the server and get the response without refreshing the page. The technolodgy of choice in this case is Javascript, which will be able to make AJAX calls.
An AJAX (asynchronous JavaScript and XML) will, as stated in its name, make an asynchronous request. But an AJAX request is just the way of doing it, it's not really a technology. Yes, javascript frameworks like Vue.js are using AJAX, but that is overkill to just make some AJAX requests.
Using Axios or even jQuery is much easier and will allow you to make a request, grab the answer and modify your page without refresh very quickly :)
[EDIT]
The process to achieve what you are looking for is pretty simple:
Use Axios or jQuery to make an AJAX call (an asynchronous request)
Handle this request with Laravel, as you do for every other request
Returns something (or not, it depends of you) to alert your user that something happened
This response will be handled by Javascript
Vue is suitable for small projects where you just want to add a little bit of reactivity, submit a form with AJAX, show the user a modal, display the value of an input as the user is typing, or many other similarly straightforward things. It's scalable and also fantastic for huge project.

Bootstrap Toggle to Update Database in Laravel 5

So i'm trying to update a user status to either enabled or disabled in the user database. I already have my toggle in place. When i view the user table from the dashboard, i want to be able to see the toggle button according to their status. I also want to be able to update their status using the same toggle.
I know it can be done with AJAX but i'm not sure about the implementation.
Anyone kind enough to enlighten me?
You are right!
You should implement it with ajax.
Firstly create a route and controller method for accessing/controlling data. Then, implement ajax call. You can use axios library for this,too. It is a very powerful library. After you send ajax call and take the response, You should manipulate DOM according to ajax response. It is a generic question and generic answer :)

ASP.NET MVC submit form

I know two ways of submitting form data: by having a button of type submit or by an AJAX post call. What is the difference between those two regarding performace?
This is a very general question, so here is a very general answer.
If you implement the AJAX call efficiently on the server, then you can expect AJAX to be more performant (when measured on the server) than a full page round-trip.
For instance, if you use ASP.NET, clicking a button to submit a page will cause a POST of the form data and a complete re-buildup and rendering of the page. That is not necessary with an AJAX call, if you use real AJAX and not the Microsoft AJAX Control Toolkit for ASP.NET.
Better to use Ajax.BeginForm instead of Html.BeginForm. It will prevent the full postback and will improve the performance.
Ajax POST
Ajax post prevents reload and postback.İt sends data to controller.
Form Data
İt occurs reload page and postback.İt sends data to controller.

Usage of Ajax form

I am an average newbie to CakePHP. While reading cookbook found Ajax form and its submission. But it lacks more details.
What are the main difference between ajax form and a normal form or What are the more specific cases we need to use Ajax form over normal form?
An example will be appreciated
Thanks....
A properly implemented Ajax form is exactly the same as a regular form, except that if JavaScript is enabled a submit handler will be bound to it that will prevent the normal submission of the form and send the data using the XMLHttpRequest object. The response will then be processed by JavaScript in the current page instead of by loading an entirely new page.
This isn't necessarily a CakePHP question, it's understanding what AJAX is.
AJAX in layman's terms is basically submitting data to a website without reloading the current page. If this is the sort of feature you want, you'll need to look into the RequestHandler component and the JsHelper in the CakePHP book for the version you are using.

Is there a way to refresh the entire page after making a ajax call

Can I refresh the whole page after making ajax calls. kindly check my code on this link for details. Actually I am saving on different server and I am making calls from different url and to see the changes refreshing the page is a must. Kindly let me know if you need more details.
problem in refreshing the page after making two ajax calls
Thanks
No point in using AJAX if you are just going to refresh instantly after. Might as well just POST and let it do the refresh there. I realize this is what was said on the other thread but it's because it makes sense. For whatever reason though, if you still want to refresh, try using the jQuery AJAX call and in your success function just do window.location.reload(), that should work.
check out my answer
problem in refreshing the page after making two ajax calls

Resources