I am working on the bookmark function when the user clicks the jQueryui button and certain information is sent to the database. But I do not use the form because there is no user login information.
I pull the user id from the session data and I send the URI segment (part of the URL)
Using codeigniter / php.
Iβm trying to understand what to put ajax / post functions in the data part, since there are no forms entered / no data and what to do with the controller βsendβ part.
controller
function addBookmark(){ if ($this->input->post('submit')) { $id = $this->session->userdata('id'); $bookmark = $this->uri->segment(3, 0); $this->bookmarks_model->postBookmark($id, $bookmark); } }
Model
function postBookmark() { $data = array( 'user_id' => $user_id, 'bookmark_id' => $bookmark, ); $this->db->insert('bookmarks', $data); }
HTML
<button class="somebutton">Add bookmark</button>
JQuery
$('.somebutton').click(function() { $.ajax({ url: 'controller/addBookmark', type: 'POST', data: ???, success: function (result) { alert("Your bookmark has been saved"); } }); });
chowwy
source share