Simple ajax query - 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: Simple ajax query (/showthread.php?tid=59902) |
Simple ajax query - El Forum - 12-06-2013 [eluser]cip6791[/eluser] Hello, I was wondering if someone can help me figure out how to include the queried data into Code: <div id="cont"></div> Code: string(2) "50" array(1) { [0]=> object(stdClass)#18 (6) { ["id"]=> string(1) "1" ["filename"]=> string(8) "filename" ["title"]=> string(5) "title" ["width"]=> string(2) "50" ["height"]=> string(2) "60" ["color"]=> string(3) "red" } } {"status":"ok","content":"50"} I would also like to know if this is the best way to query the database and display data with ajax. Thanks view Code: <form method="post" acti> js file Code: $("#submit").click(function (e) { Controller Code: public function get_items() model Code: function one_exp($width) { Simple ajax query - El Forum - 12-11-2013 [eluser]Kiran K[/eluser] Hi , Instead of $('div#cont').text(data), its better to use $('div#cont').html(data). Here you need to decode the data , which is the ajax request response before outputting it into html dom. try using using obj = JSON.parse(data); console.log(obj .item); Thanks |