将数据从js保存到php失败

I run the following js:

$(".save_post").on("click", function() {
  var saveId = $(".my_post_id").attr("data-id");
  console.log(saveId);
  $.ajax({
    url: "save.php",
    data: saveId,
    dataType: 'json',
    type: 'POST',
    success: function(json_object) {
      console.log(json_object);
      $(".save_post").text("Data has been saved.");
    },
    error: function(json_object) {
      console.log(json_object);
      $(".save_post").text("Failed to save data !");
    }
  });
});

console.log(saveId); gives 248 which is what I would like to save.

PHP page

$post_data = $_POST['data'];
if (!empty($post_data)) {
    $file = fopen('data_save.json', 'w+');
    fwrite($file, json_encode($post_data));
    fclose($file);
    echo json_encode('success');
}
var_dump($post_data);

I get if I go to save.php i get the following and the button text after I click says Failed to save data !

Null

Made it work by removing dataType: 'json',

Try this

$(".save_post").on("click", function() {
    var saveId = $(".my_post_id").attr("data-id");
    console.log(saveId);
    $.ajax({
      url: "save.php",
      data: {saveId:saveId},
      dataType: 'json',
      type: 'POST',
      success: function(json_object) {
        console.log(json_object);
        $(".save_post").text("Data has been saved.");
      },
      error: function(json_object) {
        console.log(json_object);
        $(".save_post").text("Failed to save data !");
      }
    });
});

Data should be passed in ajax like {data:data}