Ajax request: 500 (Internal Server Error) I am using this jQuery plugin to render a toggle button in a block. When the button is toggled off/on I want to write to a databse table (with entity_save). Here's the relevant code I'm using to try to acheive this:

// hook_menu item
$items['product-status-update'] = array(
  'title'=&gt;'Status update',
  'page callback' =&gt; 'my_module_status_update',
  'access callback' =&gt; 'product_entity_access', 
  'type'=&gt; MENU_CALLBACK,
);

// jQuery
drupal_add_js('
  (function($) {
    $(function() {
      $(".toggle-button").toggles({' . $status . $state . '});
      $(".toggle-button").on("toggle", function (e, status) {
        status = status == true ? 1 : 0
        $.ajax({
          type: "POST",
          url: "?q=product-status-update",
          data: "pid="+' . $pid . '&amp;"status="+status,
        });
      });
    });
  })(jQuery);
', 'inline');

// Callback
function my_module_status_update() {
  $pid = $_POST['pid'];
  $status = $_POST['status'];
  $product = entity_load_single('product', $pid);
  $product-&gt;status = $status;
  entity_save('product', $product);
}

// Console log output when toggling
POST http://example.com/?q=product-status-update 500 (Internal Server Error) jquery-1.10.2.js:8706
1 ?q=home:98
0 ?q=home:99
POST http://example.com/?q=product-status-update 500 (Internal Server Error) jquery-1.10.2.js:8706
1 ?q=home:98
1 ?q=home:99
POST http://example.com/?q=product-status-update 500 (Internal Server Error) jquery-1.10.2.js:8706
1 ?q=home:98
0 ?q=home:99


As you can see from the console log output I am receiving: 500 (Internal Server Error).

Any ideas why or what might be the culprit? Thanks.
At a glance, there's some issues with the code, however, the main error may be:

$product = entity_load_single('product', $pid);


where you don't have a $pid value, you're setting $fid instead.

$fid = $_POST['pid'];