(solved)help with jQuery, form plugin and cascade dropdown |
[eluser]jozeunico[/eluser]
Hi, well my problem it's probably that I don't understand good AJAX request with jQuery, even I don't have a clear idea about how to implement jQuery in CI. I want to make dropdown in cascade (the most classic example it's when you choose your country and automatically populate a second dropdown with it states) I have this view: Code: <html> And this controller: Code: <?php and also here it's the model Code: <?php The database just have 2 tables (estados and pais) here it's the sql for create them and fill them Code: CREATE TABLE IF NOT EXISTS `estados` ( The only thing that my app do it's to populate the a second dropdown, but until make click on the submit button, i want to send the ajax request when change the first dropdown. Well, any help thank you and thanks for your time too and I'm sorry about my english. form plugin: http://malsup.com/jquery/form/#
[eluser]nmormino[/eluser]
Seems to me like you're taking the round about way. I would forget the form plugin and just go with something like this $(document).ready(function() { $('#id_country').change(function() { $.ajax({ type: "POST", url: "some.php", data: "country="+$('#id_country').val(), success: function(data){ $('#estados').html(data); } }); }); what this function does is, when you select something from the first drop menu, it will send that value to whatever you have in your url field as post data, then take what that url returns and sticks it in your estados div. I haven't tested it, but it should do the trick.
[eluser]jozeunico[/eluser]
Well, the reason because I didn't use that method it's, well even I am learning without "way", and now my doubt about that solution it's in the "url:" what url use for set a function from a controller ? My controller it's called "comment.php" and the function where I make and echo it's "index" I try with "comment/index", "comment","comment.php/index","comment.php" but nothing happend, Just that and thanks
[eluser]jozeunico[/eluser]
Quote:Well, the reason because I didn’t use that method it’s, well even I am learning without “way”, and now my doubt about that solution it’s in the “url:” I solved the last doubt with this Code: CI_ROOT = "<?php echo base_url() ?>"; and then at the ajax request Code: url:CI_ROOT+"index.php/comment/index" (http://ellislab.com/forums/viewthread/97212/) Maybe it's not the best solution but it works. Thanks a lot
[eluser]nmormino[/eluser]
you're right on track with it, you could actually make it shorter by just using url: "<?= base_url()?>index.php/comment"; |
Welcome Guest, Not a member yet? Register Sign In |