Using ajax to load a view... |
[eluser]Wonder Woman[/eluser]
Ok I need to get my head around this...sorry if I seem dumb 8-/ When the form is submitted the controller looks at the post values and does all of the validation magic and checks to see if it's ok...when it does this it is essentially refreshing the page isn't it? I think I need a tutorial or some code to point me in the right direction...
[eluser]Sean Gates[/eluser]
Here is the order of operation: 1) Make the POST using jQuery.post(), but with some kind of data flag that says "I'm an ajax request, not a normal web page request". 2) In the controller, handle the post as normal, but don't show the view if the ajax parameter is set. Rather, show a response that the post was successful. If errors, say there were errors and handle that in jQuery to tell the user. 3) If the post was successful, then load up the new view using $.load(), kinda like: Code: $('#element_to_append_to').load('http://yoururl.com/controller/method #new_form_id'); 4) Repeat for the next form, etc. Hope that helps. EDIT: Small clarification about the ajax parameter in the controller.
[eluser]nuwanda[/eluser]
The Nettuts Codeigniter series is excellent. This is the login tutorial which will show you how to reload the same controller and show errors. http://net.tutsplus.com/articles/news/co...y-6-login/ You don't need different views. You just need to test for errors in the controller and reload the same view. The view then shows the errors. Ajax won't help you with that. In fact, it'll complicate things. Use ajax for small operations that enhance the user experience. Reloading a view is no big deal.
[eluser]Sean Gates[/eluser]
@nuwanda: That's not what @ffp is trying to accomplish. Ajax is the only way to avoid a page refresh. As @fpp said, the current forms work as intended without JS, so your links are a moot point.
[eluser]Wonder Woman[/eluser]
I have my ajax refresh working, yay! Just a couple of tweaks and it will be fully working. Thank you.
|
Welcome Guest, Not a member yet? Register Sign In |