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 :)
Related
i need some help. I want to make my tables update the status when i click refresh button. But can i make it without refreshing the page? Like just the value on the table that updated. Something like re-render in javascript when there is an update to the state..
There are so many ways to accomplish what you are asking... some examples here:
You could use a javascript ajax that ask for the updated table and
reload it when you click refresh.
You could use a javascript ajax that ask only for changes and update
only changed fields.
You could set and Interval with setInterval that ask for changed
values automatically.
For something more tricky: you could manage a serverSocket for push updates to client and trigger javascript to manage the updating
data
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.
In facebook after I shared something in my wall I get a nice pop message about my activity. Sometimes whenever there is an error with they gave a nice pop about the error. Like this.
I know in facebook everything is about ajax.
I am creating a web application using mvc 3 asp.net. In my web app there is something similar to sharing links like in facebook.
I implemented this feature using ajax and partial views and it is works fine.
When user submit a new link, In my controller action method I update the db and return a partial view finally update my view with nice animation.
Now my problem is how can I give a pop up response while updating my view(facebook wall).
I want to do both of them with the ActionResult.
I not sure this is the correct way to do this.
Briefly what I want is update my view with automatic pop up response. Hope you understand what I want.
Let me know If you need any clarification on this.
Please help me to implement this function.
Thanks !!
Well a "popup" is client-side functionality, not server-side. You can't do it with actionresult per-se.
Perhaps you should return a PartialViewResult from an action method, which is fired by an AJAX call (e.g jQuery).
Then in the callback, set the HTML of a hidden container/div to the partial view's HTML, then show it in a fancy way.
Something like jQModal or jQuery UI dialog is perfect for this.
I found the answer myself. Add Jquery library and unrobustive javascript and
return JavaScript("alert('Some message')");
In mvc sitemap provider I want to show a list menu's based on the id of the logged in user.I was thinnking about dynamicnodeprovider but it is working for the first request it self that is before logging in.How can i achieve this?
Thanks,
Ajai
You could use cookies to achieve that. Set a cookie when the user logs in and read it when he comes back. Obviously this wouldn't work if:
the user blocks cookies
the user visits the site for the very first time
so you would need a default view for first visits; i don't think you can avoid this problem.
You could take the approach of making a JQuery AJAX call to a controller method which returns the required sitemap information. This enables you to update the sitemap whenever you like based on client side events.
e.g. see this post : http://joelabrahamsson.com/entry/xml-sitemap-with-aspnet-mvc
Another decision is if you want the controller to return the sitemap as ready generated HTML and dynamically replace it in the DOM. Or ( more work ) return the pure sitemap in XML and have JQuery generate the SiteMap markup for you.
I read some paragraphs in a book saying that it is not possible to do a partial postback for web, even AJAX is employed. Ajax will postback everything and update only ajaxfied controls.
However, on pages I made using ajax, I used Fiddler to monitor the transportation. I found when the page initial load, it loaded everything include pictures .... However, when I click a button and do a ajax postback. I can only see the some data were loaded.... Looks like it doesn't need to reload the whole page again.
I don't know if what I see is correct? Or the book I read is correct?
Thank you guys.
That depends what you put in the term "postback".
The AJAX call will send the complete form data back to the server, just as if the form was posted normally. The server will answer with a partial response that only contains the parts of the page that should be updated.
So, the request is not partial, but the response is.
I am not sure how you are posting back from the client side. I am guessing you are using UpdatePanels. How well you 'AJAX-ify' a web page depends on what method you employ.
UpdatePanels - Read Dave Ward's posting on them - http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/
PageMethods to post back to a web service, get the data and update the DOM to display the result
JQuery and other such AJAX frameworks to post back to a web service
I am sure the link above should clear things up a bit
I'm having a hard time understanding your terminology. I'm not really sure what a "postback" is, much less a "partial" one. I do know that one of the basic ways to transmit information to an HTTP server is via a POST request, which is usually used when submitting forms. If you mean to say that the entire form is transmitted when you click a submit button, I believe you'd be right.
You also seem to be doing something with AJAX, but it's difficult to tell. The whole point of AJAX is to have dynamic data displayed on a page without resorting to reloading it. Defining what to send and what to do with the results is entirely up to your own JavaScript. So unless you're using a framework, which you don't specify, there is no such thing as "ajaxified controls."
In any case, "AJAX" usually means using the XMLHttpRequest() method of modern browsers to send data to servers without refreshing the page. When you call this function, you specify exactly what data to send. This has nothing to do with HTML forms. One caveat: if you are indeed using a library for AJAX, it might impose additional limits on how you structure information to send.