Ajax发布了意外的数据类型


Ajax Posts unexpected datatype

我已经用这段代码头疼了几个小时了。。

提取SQL记录并制作foreach的删除按钮:

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    extract($row);
          $html.= <a onclick='return Delete($row[id])' href='javascript:void(0)' title='Remove this record'>Remove</a>
}

麻烦来了:

  <script type='text/javascript'>
           function Delete(id)
            {
              if(confirm('Are you sure you want to delete this row?')==true)
                $.ajax({
                   type: 'POST',
                   url: 'delete.php',
                   data: id,
                   success: function (data) {
                   }
                  });
             }
  </script>

到目前为止还不错,但当我做时

var_dump($_POST); 

在delete.php中查看我得到的信息,而不是ID(INT)

array(1){["formatMoney"]=>string(4)"0,00"

注意:我试图将dataType设置为:"string",但得到了相同的效果。

我想我做错了什么。如果有人能指引我正确的方向。我真的很感激。

试试这个:-

data: {id:id},

在服务器上获取id作为

<?php echo $_POST["id"];//here you get id ?> 

以及在发送ajax请求之前,通过功能启动中的警报检查id

function Delete(id)
{
    alert(id)
    if(confirm('Are you sure you want to delete this row?')==true)
}