title: click jquery button + send data without form - bookmark
body: <p>I'm working on a bookmarking function where the user clicks on a jQueryui button and certain information is sent to the database. But I'm not using a form, because there is no information for the user to enter. </p>
  
  <p>I'm pulling the user's ID from the session data, and I'm sending a URI segment (portion of the URL)</p>
  
  <p>Using codeigniter/php.</p>
  
  <p>I'm trying to figure out what to put in the data portion of the ajax/post function, since there's no form/no data entered, and what to do about the "submit" part of the controller.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>function addBookmark(){
  
          if ($this-&gt;input-&gt;post('submit')) {
  
              $id = $this-&gt;session-&gt;userdata('id');               
              $bookmark = $this-&gt;uri-&gt;segment(3, 0);
  
              $this-&gt;bookmarks_model-&gt;postBookmark($id, $bookmark);
          }
  
      }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>function postBookmark() {
  
       $data = array(
              'user_id' =&gt; $user_id,
              'bookmark_id' =&gt; $bookmark,
      );
  
      $this-&gt;db-&gt;insert('bookmarks', $data);
  
      }
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;button class="somebutton"&gt;Add bookmark&lt;/button&gt;
  </code></pre>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$('.somebutton').click(function() { 
  
              $.ajax({
                  url: 'controller/addBookmark',
                  type: 'POST',
                  data: ???,
                  success: function (result) {
                    alert("Your bookmark has been saved");
                  }
              });  
  
      });
  </code></pre>