使用json和php的Ajax MSSQL查询返回未定义的数组

使用json和php的Ajax MSSQL查询返回未定义的数组,php,sql-server,ajax,json,Php,Sql Server,Ajax,Json,我在发出警报(数据[I].name)时遇到问题。即使返回数组,结果也是未定义的。有人知道问题出在哪里吗 这是我的Javascript $('#plus').click(function(){ $.ajax({ type : 'POST', url : 'jqueryDBactionview.php', dataType : 'json', data: { }, success: function( d

我在发出警报(数据[I].name)时遇到问题。即使返回数组,结果也是未定义的。有人知道问题出在哪里吗

这是我的Javascript

    $('#plus').click(function(){
    $.ajax({
        type : 'POST',
        url : 'jqueryDBactionview.php',
        dataType : 'json',
        data: { },
        success: function( data){
            $.each( data, function(i, item) {
                alert( data[i].name);
            });
        }
    });
});
这是我的php

$query = "SELECT TOP (1) * ";
$query .= "FROM maillist WHERE bolag = 'FAL'";
$results = mssql_query($query);
$result = array();
while($row = mssql_fetch_array($results))
{
  $result[] = array(
          'id' => $row['id'],
          'company' => $row['company'],
          'name' => $row['name'],
          'mail' => $row['mail']
       );
}
echo json_encode($result);

请使用JSON.parse(data)转换JSON编码的结果,然后在每个循环中使用它

您有
data:{}
empty…请检查my answerdata{}用于发送带有Ajax请求的post变量,该请求为空,但数据是success函数的参数,因此,无论Mysql$result返回的值是什么,都会传递到functionwhy use post的数据参数?它应该是get方法,提问者不会将任何内容发布到服务器,而且我希望我的sql查询也不是很好的格式,我从未在php中工作过,但在标准方式下似乎是错误的