使用Mojolicious:在javascript中访问perl哈希,通过ajax调用作为json传递

时间:2017-10-05 20:30:08

标签: json perl mojolicious dbix-class

如何通过密钥访问我的json哈希?

我有一个ajax电话

function populate_technician_info(public_info_id)
{
  var advantage_id = $('#admin_info').data('advantage_id');

  $.ajax({
    type: 'POST',
    url: '/ajax/get_technician_info',
    data: {'advantage_id': advantage_id},
    dataType: "json",
    success: function(tech_1_info, tech_2_info)
    {
      alert(tech_1_info);
      add_technician_row(tech_1_info, tech_2_info, public_info_id);
    }
  });
}

enter image description here 和一个java脚本函数来填充信息返回(现在它只是一个警报)。

function add_technician_row(tech_1_info, tech_2_info, public_info_id)
{
  public_info_id = '#' + public_info_id;

  $.each([tech_1_info, tech_2_info], function(index, value)
  {
    $.each(this, function (tech_index, tech_info)
    {
      alert("Tech 1: " + tech_info.empl_first_nm);  
    });
  });
}

我的问题是如何通过密钥访问值? 我试过了明显的tech_info.key 但我没有运气,它返回undefined或哈希对象。 enter image description here

但如果我只是打印tech_info我就会得到 enter image description here

所以我知道我有正确的对象。

数据绝对存在我通过打印从perl到终端的值来仔细检查它。 enter image description here

my $technician_1_results = $self->employee_data_hub->resultset('Advantage')->search({employee_id => $tech_1_employee_id});
my $tech_1_info = $technician_1_results->first;
$self->render(json => {tech_1_info => $tech_1_info, tech_2_info => $tech_2_info});

0 个答案:

没有答案