![]() |
How to call CI Model function from jQuery eventhandler? - 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: How to call CI Model function from jQuery eventhandler? (/showthread.php?tid=9045) |
How to call CI Model function from jQuery eventhandler? - El Forum - 06-10-2008 [eluser]JoostV[/eluser] Hi there, How can I make a jQuery eventhandler call a function from a CI Model? I would like to call the following function automatically when a user closes the browser window. (the functions saves the user's moderations) Code: $this->articles->save($id); jQuery $(window).unload seems to be the perfect eventhandler for this task. Code: $(window).unload( function () { /*Do_Stuff*/ } ); But how do I make this event call my CI Model function? How to call CI Model function from jQuery eventhandler? - El Forum - 06-10-2008 [eluser]xwero[/eluser] The models are not supposed to be called directly from a url. That is the job of the controller. How to call CI Model function from jQuery eventhandler? - El Forum - 06-10-2008 [eluser]JoostV[/eluser] OK, but how can I let jQuery call a controller that in its turn will call the model method save()? How to call CI Model function from jQuery eventhandler? - El Forum - 06-10-2008 [eluser]xwero[/eluser] using it ajax functions. If you don't need feedback you can use the get or post methods, if you want more flexibility use the ajax method. For your example it would be something like Code: $(window).unload( function () { $.post('index.php/controller/method',$(":input").serializeArray()) } ); How to call CI Model function from jQuery eventhandler? - El Forum - 06-10-2008 [eluser]JoostV[/eluser] OK, I'll get that working. I got lost in jQuery documentation. Thanx! How to call CI Model function from jQuery eventhandler? - El Forum - 06-13-2008 [eluser]doni[/eluser] and how about if i do need feed back?,let say i'm passing form value to CI's controller and i need feed back to my previous page to let know the user that their data has been saved to DB.. Code: $('#update').click(function() { Code: function update() |