成功函数不使用ajax返回数据

The success function does not give results. How do I solve this?

I have the following code

function fun()
{
  var list_target_id = 'year';
  $.ajax({
    url: '://localhost/htdocs/cscart_mutli_car/index.php?dispatch=drill.drill',
    dataType: 'json',
    success: function (data) {
      alert(data);
    },
    error: function (xhr, status, error) {
      alert(xhr.responseText);
    }
  });
}



if ($mode == 'drill')
{
  $id = 166;
  $arr = array('category_id' = > 167, 'category' = > 'computers');
  echojson_encode($arr);
  exit;
}

Here in this Ajax I get the success alert. But it does not provide any results. How do I solve this?

The data which is returned in the success handler is an Object.The alert will alert the string representation of the Object i.e. data.toString() which is [Object object]

You can get required things from data by calling properties from data object like this.

alert(data.category_id);

and

alert(data.category);