duanfei1987 2016-07-08 12:57
浏览 27

解码json数据并将其存储在数组中

I am fetching some json data using ajax call,and data is coming like ["2","Learn Python"],first field of this json data is id of result.

Problem is, I have to store this id in some other array and pass via url on some form submission.

Let me explain the scenario

  1. initially user searches for result via search bar.

  2. Results will appear and a checkbox associated with each result.

  3. When user click on checkbox ajax call generated and it fetches related data to this result and show it in some hidden div's.

  4. now result coming in hidden div's after ajax call will be compared by user.

so I need to pass each fetched result id's using url

my ajax call code is

$(document).ready(function() {
  $(".compare").change(function() {
    if(this.checked) {
      $('#compare_box').show();
      var check = $(this).val();      
      $.ajax({
        type: 'POST',
        url: 'compare.php',
        dataType : 'JSON',
        data:{value : check},
        success: function(data) {
          console.log(data);
          //var boxes[check] = [];
          //boxes[check] = $(data);
          id = [];
          $('#result').append(data); 
        }
      });
    } else if (!this.checked && boxes[check]) {
      boxes[check].remove();
      delete boxes[check];
    }
  });
});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 求数学坐标画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站