Quick JS Question - 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: Quick JS Question (/showthread.php?tid=37561) |
Quick JS Question - El Forum - 01-13-2011 [eluser]veritascs[/eluser] I'm newish to javascript and having a little trouble. I got the AJAX part down, I just don't know how to handle the returned array in JS (or maybe I'm passing it incorrectly from CI). Anyway, here is my JS (using jQuery): Code: function getCat(obj) { My controller: Code: function getCat() { And my model: Code: function getCategoryInfo($category, $column_name = 'category_id') { Quick JS Question - El Forum - 01-13-2011 [eluser]CroNiX[/eluser] Its because your are sending php arrays to the javascript. In your controller, use something like echo json_encode(array('result' => $category)); Then in your javascript callback... function(data){ alert(data.result.category_name); //now you use javascript object } Don't forget to set the "type" of your $.post to "json" Quick JS Question - El Forum - 01-13-2011 [eluser]veritascs[/eluser] Thanks a bunch |