Get Mysql insert_id in java - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Get Mysql insert_id in java (/showthread.php?tid=1213) |
Get Mysql insert_id in java - Marcel - 02-19-2015 Hi all im new to codeignighter and seem to be having ap roblem with retriving the last insert_id. what im doing first of all im not using a form i catch the button id from java and call my controller function like so Code: $('#statusupdate').click(function(){ // when user click no move to next profile and save choice to db my controller then calls a function in my model like so Code: function set_post($message){ my model looks like so Code: public function add_status_post ($guid,$message,$type=0,$data=0) { how can i get this user id in my java script ? by the way the row does get inserted thanks RE: Get Mysql insert_id in java - Marcel - 02-19-2015 ok all just to let you know i found a solution i added these two lines to my controller function Code: $this->output->set_content_type('application/json'); and changed my java like so Code: $('#statusupdate').click(function(){ // when user click no move to next profile and save choice to db if my coding looks bad let me know thx RE: Get Mysql insert_id in java - CroNiX - 02-19-2015 If you are sending something back in an ajax request, you don't "return" it. That returns something back to your PHP script and NOT your browser. You output/echo something back to the browser. Instead of Code: return $data; Try Code: echo json_encode($data); Then in your javascript success event: Code: function(data){ Then check the js console of you browser. You should see a json object which contains 'post_id' and its value. RE: Get Mysql insert_id in java - Narf - 02-19-2015 FYI, Java is a different thing from JavaScript ... if you continue to call it that way, fellow programmers will make fun of you. |