通过ajax jquery发布

I want to send my subId Value with jquery ajax to server and insert that into my table "b_wing" which the column is "wing"...I can do it, if I change the value of the column manual ...So the url is found! but I think the 'subId' can't be found!!! I'm already get the value of the clicked element , but nothing happend when I POSTed it. Here is my JavaScript code.

$('.subject').click(function () {
  var subId = $(this).val();
    alert(subId);

     $.ajax({
      url: '/framework/profile/wing/',
      method: 'POST',
      data: {
          subId: subId
      }
}).done(function (data) {
      $('#wing').toggle();
    });


});

And here is my php code

public function wing() {
$subId = $_POST['subId'];
$db = Db::getInstance();
$wingers = $db->insert('INSERT INTO b_wing (wing) VALUES ($subId)');
require_once('/mvc/view/profile/admin.php');

}

What should I do?

In the POST request in your question, jquery was just adding [object Object] to the query string which means that nothing was getting through to your server... Since your PHP controller is expecting the subId in the form data of the POST request, it's probably best to use this syntax to get your data through to the server as it expects it:

$.post('/framework/profile/wing', { subId: subId }, function(returnedData) { console.log(returnedData); $('#wing').toggle(); });

This syntax above will also set up the correct HTTP headers for Content-Type, etc. and parse the response.

In the sql query string, you have used single quotes. Change them with the double quotes.

public function wing() {
    $subId = $_POST['subId'];
    $db = Db::getInstance();
    $wingers = $db->insert("INSERT INTO b_wing (wing) VALUES ($subId)");
    require_once('/mvc/view/profile/admin.php');
}

Also, 1) My assumption is that $subId is an integer. 2) Use parameterized query while inserting any data coming from user/client/frontend.