jQuery - 使用ajax从更改页面停止表单提交

I am trying to submit a form without reloading the page. I have tried using this script with no success:

$('#formId').submit(function(e){
    $.ajax({
        type: "POST",
        url: 'serverSide.php',
        data: $('#formId').serialize(),
        success: function(data){
            alert(data);
        }
    });
    e.preventDefault();
});

Does anyone know what I am doing wrong?

Using return false will usually do the trick

$('#formId').submit(function(e){
    $.ajax({
      type: "POST",
      url: 'serverSide.php',
      data: $('#formId').serialize(),
      success: function(data){
        alert(data);
      }
    });
  e.preventDefault();
  return false;
});

Try putting preventDefault before the AJAX. This way the default actions are prevented before the ajax-request is triggered

$('#formId').submit(function(e){
    e.preventDefault();
    $.ajax({
        type: "POST",
        url: 'serverSide.php',
        data: $('#formId').serialize(),
        success: function(data){
            alert(data);
        }
    });
});