Javascript ajax,变量未定义?

Javascript ajax,变量未定义?,javascript,php,json,ajax,Javascript,Php,Json,Ajax,我找不到我的代码有什么问题。从post_receiver.php打印json文件时,会相应地打印json 从post_receiver.php打印的JSON <?php session_start(); ob_start(); require_once('../../mysqlConnector/mysql_connect.php'); $result_array = array();

我找不到我的代码有什么问题。从post_receiver.php打印json文件时,会相应地打印json

从post_receiver.php打印的JSON

     <?php 
      session_start();
      ob_start();                    
      require_once('../../mysqlConnector/mysql_connect.php');
       $result_array = array();

   $query="SELECT COUNT(initID) AS count, urgency, crime, initID, TIMESTAMPDIFF( minute,dateanalyzed,NOW()) AS minuteDiff FROM initialanalysis WHERE commanderR='0' AND stationID='{$_SESSION['stationID']}';";

 $result=mysqli_query($dbc,$query);
   if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {

      array_push($result_array, $row);

      }

                            }
    echo json_encode($result_array);
                            ?>
我的ajax代码:

$.ajax({
        method: 'POST',
        url: "post_receiver.php",
        data: {
            'count': count,
            'urgency': urgency
        },...

“count”和“currency”变量没有定义,我对JSON格式不太熟悉…

success
回调中,您会得到一个
数据
字符串,其中包含响应。要将其解析为JSON,请使用
JSON
dataType
设置:

$.ajax({
  method: 'POST',
  url: 'post_receiver.php',
  dataType: 'json',
  success: function (data) {
    // 'data' contains the parsed JSON
    console.log('Count:', data[0].count); // read the values from the JS object and log them to the console
    console.log('Urgency:', data[0].urgency);
  }
});

data
字段指定将哪些请求参数发送到服务器。您想发送一个
计数
序列
值,还是想从响应中提取它们?@PeterMader我想从响应中提取值这不起作用。不是成功的ajax,而是错误捕捉器。添加了我的php代码,它只是在控制台中打印结果。“错误:函数(XMLHttpRequest,textStatus,exception){console.log(XMLHttpRequest.responseText);”我不需要看到
错误
回调,我需要错误消息。错误控制台上打印了什么?
$.ajax({
  method: 'POST',
  url: 'post_receiver.php',
  dataType: 'json',
  success: function (data) {
    // 'data' contains the parsed JSON
    console.log('Count:', data[0].count); // read the values from the JS object and log them to the console
    console.log('Urgency:', data[0].urgency);
  }
});