![]() |
CI, jQuery, and a Database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CI, jQuery, and a Database (/showthread.php?tid=7091) |
CI, jQuery, and a Database - El Forum - 03-24-2008 [eluser]phusiondesign[/eluser] I need some help understanding how to relate Code Igniter to jQuery and how to interact the two. I am using jQuery w/ the form plugin. If someone could point me to a tutorial which shows how to have a input field which is submitted using json and jquery and then is inserted into a database and then then a success message is shown on the page. I know this probably easy, but I am having a hard time figuring it out... even with the examples at jquey.com. Thanks. I think this is because I am passing the values incorrectly around within in CI. CI, jQuery, and a Database - El Forum - 03-24-2008 [eluser]Jay Turley[/eluser] I don't have a pointer to a tutorial, but here is how I did it: 1. Make the form-database work without jquery in the mix at all. 2. Include jquery on the form page, then use jquery to replace the form submit with an ajax call. a. I typically set the form action to '' b. I typically use serialize() to get the form elements ready for sending (use serializetoarray() for JSON notation) c. I typically call the ajax pointing it to an ajax-only controller which will return a JSON view. This is called progressive enhancement, and should be used in most cases when adding Ajax to a web application. Make it work first, then layer the ajax on top. CI, jQuery, and a Database - El Forum - 03-24-2008 [eluser]phusiondesign[/eluser] Thanks for the help... Here is what I have so far and hope that someone can help me to get it working. It gets to the point where it alerts me before it does the ajaxSubmit. Model: Code: <?php Controller: Code: <?php View: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> I am probably making some obvious mistake... thanks in advance. CI, jQuery, and a Database - El Forum - 03-24-2008 [eluser]Jay Turley[/eluser] [quote author="phusiondesign" date="1206429175"] Code: $(function(){ I am probably making some obvious mistake... thanks in advance.[/quote] Okay, maybe I am missing something, but it doesn't look to me like you are using the Form Plugin for jquery. Instead, your syntax above looks exactly like the typical form for a plain jQuery Ajax submission. Try changing this line: Code: $('#form1').ajaxSubmit({ Code: $.ajax({ CI, jQuery, and a Database - El Forum - 03-25-2008 [eluser]phusiondesign[/eluser] I tried that earlier and again just now and it didn't give me any luck either time. From what I can tell it is either not posting the data correctly to the controller or my controller is not handling the information correctly. Still need some help. Thanks! CI, jQuery, and a Database - El Forum - 03-25-2008 [eluser]phusiondesign[/eluser] I have changed my ajax call to a script data type and the controller to handle it accordingly, and everything is working.... but I did not utilize json and would really like to understand how and why it wasn't working. Thanks everyone for the help. Controller: Code: function add() { Ajax Call: Code: $(function(){ CI, jQuery, and a Database - El Forum - 03-26-2008 [eluser]Merolen[/eluser] Hi, I've actually been working with jQuery and JSON today. Think I'm starting to understand it all. For some reason it didn't work, but after a while (the next day) it suddenly worked. Maybe I did something to it or maybe there is some kind of strange caching I don't know of. In the success: are you doing: Code: success: function(data){ Also defining Code: error: function (data, status, e){ alert('error: ' + e); } You have tried everything? removeing the "" inside the json-string? Or changing the ' ' to " " Code: // This one works for me These are my initial experience with jQuery and json, hope it helps |