title: using jQuery to get url and extract url segments
body: <p>On a webpage that has a list of categories, and each category title is linked in this format: <code>http://localhost/admin/category/unpublish/2</code></p>
  
  <p>I wrote the following js code, trying to capture the url and the segments 'unpublish' (action) and '2' (id), and need to send the request to <code>http://localhost/admin/category</code></p>
  
  <pre class="lang-js prettyprint-override"><code>$('#statusChanges a').click(function(evt) { // use the click event of hyperlinks
    evt.preventDefault();
    var url = $(location).attr('href');
    // var action = url.segment(3);  /*JS console complains that url.segment() method undefined! */
    // var id = url.segment(4);
    $.ajax({
      type: "GET",
      url: $(location).attr('href'),
      dat: '',
      /* do I need to fill the data with json data: {"action": "unpublish, "id": 2 } ? but I don't know how to get the segments */
      success: function(data) {
        $('.statusSuccess').text('success!');
      },
      error: function(data) {
        $('.statusSuccess').text('error!');
      }
    });
  }); // end of status change
  </code></pre>