Ajax Framework (CJAX) for Codeigniter 2.x+ |
[eluser]MonsterTKE[/eluser]
<_< Well that would make more sense. Working now.
[eluser]MonsterTKE[/eluser]
Ok I am 2-3 hours into learning this Librarys API, and so far it is awesome, I have pretty much reimplemented most of the examples to learn from. This may be a general AJAX question but consider the scenario I have. 1. url. /rating/add/28/up . This is all server side, no post data, I grab some session info and user_id from tank_auth. The /28/up part is sanitized by hand with some if statements. 2. The controller redirects to the base_url on success (ahem, AJAX), or to one of two error pages, a general error, and a "sorry you cant vote twice" page. If they arent logged in it redirects to /auth/login. So my question is... Can I run that function via AJAX, load the views for the errors if necessary(in an overlay) and here is the kicker, on success, open a comment form in an overlay to submit a comment using all of the validation data I collected when the link was first clicked? I can probably hack this together using a few different functions and a new form view, Im just hoping there is some easy way to do this. (I should mention all of the /rating/add/#/up|down links are presented in the view with a foreach, Im assuming I would have to add the $ajax-> methods using a foreach to setup the div ids?)
[eluser]Ajaxboy[/eluser]
1. These broad questions, and there are many ways of accomplishing the objective you are after. Generally speaking, instead of redirecting to an error page, generally in the ajax framework you may display error messages on the screen eg: $ajax->error("Error Message Here") or warnings; $ajax->warning("Warning Message Here") ; 2. If you actually wish to redirect to the base url you can do: $ajax->location(base_url()); Quote:So my question is... Can I run that function via AJAX, load the views for the errors if necessary(in an overlay) and here is the kicker, on success, open a comment form in an overlay to submit a comment using all of the validation data I collected when the link was first clicked? Yes, you can load a view in an overlay. Just do: $ajax->overlayContent($this->load->view('your_template_view_here', null, true)); So now your question relates to the validation plugin... Since the form doesn't exist on page load, You would need to trigger the validate plugin from the ajax response and add validation to that form just after you run the $ajax->overlayContent() command which displays the form. just make sure you run the validate plugin command after the overlayContent that displays the form and not before to avoid retroactive action.
[eluser]MonsterTKE[/eluser]
Cool, I spent a few minutes thinking about a code flow for this. Mainly I am trying to keep the backend behavior and the comment/whatever part of the same series of actions. Code: foreach ($result as $row) Thats about it I think, and probably as hard as I have had to think about implementing something so far. Thanks again for your help ![]()
[eluser]Ajaxboy[/eluser]
that's your pseudo code.. first separate your view from your from your ajax controller.. Lets say this is your view.. Code: <?php Then handle the ajax controller // controller handler.. in your ajax application/response/x_class.php - x_class::do_some_things() Code: class x_class extends CI_Controller {
[eluser]Ajaxboy[/eluser]
You may need a small change in the plugin in plugin file cjax/plugins/validate/validate.php add this function, in plugin class validate: Code: function onAjaxLoad($button_id, $post_url, $rules = array())
[eluser]MonsterTKE[/eluser]
[quote author="Ajaxboy" date="1340538966"]You may need a small change in the plugin in plugin file [/quote] I have all of the stuff discussed yesterday implemented, but with a slight problem. The ajax calls dont seem to be surviving the foreach loop I am using to build the page. It works just fine on the base url page, but when I click on a pagination link to go to page 2 or greater, the links Im using to call the ajax with just turn into regular anchors. What else is surprising is if I call the page with the controller and method in the url it also doesnt work.
[eluser]Ajaxboy[/eluser]
Try doing it in your CI controller instead of on the view. It is possible that the JavaScript lib is being loaded before the statement in the view, so it won't pick these commands retroactively. Eg: In your Controller Code: foreach ($result as $row) { Then in your view do your anchors: Code: foreach ($result as $row):
[eluser]MonsterTKE[/eluser]
[quote author="Ajaxboy" date="1340614019"]Try doing it in your CI controller instead of on the view. It is possible that the JavaScript lib is being loaded before the statement in the view, so it won't pick these commands retroactively. [/quote] It behaved the same with the $ajax->Exec forloop in the controller. Works Just fine for the first 5 links. http://monstertke.zapto.org (red and green vote counters) calling the controller and function directly http://monstertke.zapto.org/vendors/index doesnt work, nor does calling it with the pagination links at the bottom of the page. Im assuming you meant to loop them in the "vendors" controller, not the ajax controller I am calling?
[eluser]Ajaxboy[/eluser]
It is recommended to use firebug (https://getfirebug.com/) for quick error debugging, it appears the path for the js lib is incorrect,So the js lib is not being loaded. This is the error I saw on your page: "NetworkError: 404 Not Found - http://monstertke.zapto.org/vendors/cjax...RC2.min.js" |
Welcome Guest, Not a member yet? Register Sign In |