在PHP中从Ajax传递数据

I want to pass data from ajax. Can anybody please tell me how is that possible??

Here is my index.php

   <form method="post" action="">
   <input type="text" id="class_name" name="class_name">
   <input type="hidden" name="user_id" id="user_id" value="<?=$user_id?>" />

   <button id="submit" name="submit" value="submit" type="submit"></button>
   </form>

and here is update.php

<?
    if(isset($_POST['submit'])) {

    user_id= $_POST['user_id'];
    class_name= $_POSt['class_name'];
    $date= date("M d , Y");

    $sql_ins="insert into chat set user_id='$user_id', class_name='$class_name', 
    time=now(),date='$date'";
    $sql_que=$db->db_query($sql_ins);
    }
?>

How can I pass this data into server via ajax not from action.?? What is the ajax script for that?? Thanks in advance

use jquery with ajax & call ajax function onclick of submit button

$.ajax('URL', {
    type: 'POST',  
    data: { myData: 'formdata' },  // data to submit
    success: function (data) {
        console.log(data);
    }        
});

You can do this with Jquery:

jQuery.ajax({
type: "POST",
url: "update.php", //your php file
data: data, //the data of your form
     success: function(html){ 
// this happen after we get result
                              }
   });

this is a tutorial: jquery ajax tutorial