如何将数组值附加到div id [json]

时间:2015-06-09 06:49:31

标签: javascript jquery ajax json

我有从Json返回的数组值。并显示所有切片名称并附加到以下div

$('user_original_id').observe('blur', function (e) {
    var txt = $('user_original_id').value;
    jQuery.ajax({
        type: 'get',
        url: BASE_URL + 'admin/index/listings',
        data: {
            user_id: txt
        },
        dataType: 'json',
        success: function (data) {}

    });
});

值为

[{
  "item_id": "3470",
  "title": "Star college",
  "attribute_set_id": "58",
  "featured": "0",
  "image1": "agriculture2.jpg",
  "logo1": "5.jpg",
  "value": "a:16:{s:5:\"title\";s:12:\"Star college\";s:17:\"short_description\";s:84:\"Star collegeStar \
  ";s:11:\"description\";s:72:\"Star collegeStar college\";s:7:\"cat_ids\";s:6:\"73,232\";i:48;s:8:\"Nkl\";i:158;s:8:\"Nkl\
        ";i: 136;s: 8: \"Nkl\";i:137;s:8:\"Nkl\";i:157;s:6:\"637410\";i:49;s:10:\"9000000004\";i:138;s:0:\"\";i:84;s:25:\
        "
  xxx@ gmail.com\ ";i:121;s:0:\"\";i:130;s:9:\"11.211583\";i:131;s:9:\"78.176977\";s:10:\"descrii113\";s:0:\"\";}
  ","
  user_id ":"
  139 ","
  short_description ":"
  Star college ","
  description ":"
  Star collegeStarcollege ","
  cat_ids ":"
  73,
  232 ","
  created_on ":
  "0000-00-00 00:00:00",
  "url_key": "star-college",
  "status": "1",
  "verification": "0",
  "city": "",
  "etc": null
}, {
  "item_id": "3471",
  "title": "Houses for rent",
  "attribute_set_id": "67",
  "featured": "0",
  "image1": "competitive-exam-training2.jpg",
  "logo1": "banks1.png",
  "value": "a:24:{s:5:\"title\";s:15:\"Houses for rent\";s:17:\"short_description\";s:300:\"Houses for rent\";s:11:\"description\";s:540:\
        "
  Houses for rent\ ";s:6:\"status\";s:1:\"1\";s:12:\"verification\";s:1:\"0\";s:4:\"city\";s:1:\"1\";s:7:\"cat_ids\";s:2:\"24\";i:147;s:3:\"200\";
  i: 112;s: 3: \"142\";i:145;s:4:\"Cash\";i:148;s:2:\"No\";i:146;s:3:\"Yes\";s:10:\"descrii113\";s:0:\"\";i:48;s:8:\"Namakkal\";i:158;s:8:\"
  Nkl\ ";i:136;s:8:\"Nkl\";i:137;s:8:\"Nkl\";i:157;s:6:\"637410\";i:49;s:10:\"9000000000\";i:138;s:6:\"235696\";i:84;s:25:\
        "
  xxx@ gmail.com\ ";i:121;s:0:\"\";i:130;s:9:\"11.211583\";i:131;s:9:\"78.176977\";}",
  "user_id": "139",
  "short_description": "Houses for rentHouses rentHouses for rentHouses for rentHouses for rent",
  "cat_ids": "24",
  "created_on": "0000-00-00 00:00:00",
  "url_key": "houses-for-rent",
  "status": "1",
  "verification": "0",
  "city": "1",
  "etc": null
}, {
  "item_id": "3472",
  "title": "Generator",
  "attribute_set_id": "61",
  "featured": "0",
  "image1": "book-binding2.jpg",
  "logo1": "borewells1.png",
  "value": "a:19:{s:5:\"title\";s:9:\"Generator\";s:17:\"short_description\";s:180:\
        "
  GeneratorGeneratorGeneratorGeneratorGenerator\ ";s:11:\"description\";s:180:\"Generator\";s:6:\"status\";s:1:\"1\";s:12:\"verification\";s:1:\"0\";s:4:\
        "
  city\ ";s:1:\"1\";s:7:\"cat_ids\";s:14:\"19,301,295,296\";i:48;s:8:\"Nkl\";i:158;s:8:\"Nkl\";i:136;s:8:\"Nkl\";i:137;s:8:\"Nkl\";i:157;s:6:\
        "
  637410\ ";i:49;s:10:\"9000000004\";i:138;s:6:\"235696\";i:84;s:25:\"xxx@gmail.com\";i:121;s:0:\"\";i:130;s:9:\"11.211583\";i:131;s:9:\"78.176977\
        ";s: 10: \"descrii113\";s:180:\"GeneratorGeneratorGenerator\";}",
  "user_id": "139",
  "short_description": "GeneratorGeneratorGenerator",
  "description": "Generator
  GeneratorGenerator ","
  cat_ids ":"
  19,
  301,
  295,
  296 ","
  created_on ":"
  0000 - 00 - 00 00: 00: 00 ","
  url_key ":"
  generator ",
  "status": "1",
  "verification": "0",
  "city": "1",
  "etc": null
}]

从上面的值我想显示所有的瓷砖名称并附加到下面的div ..如何做到这一点...提前致谢

<div id="listings_categories" class="fieldset subgrouplistings_categories">
<i class="icon icon-pencil"></i>
No listings
</div>

1 个答案:

答案 0 :(得分:0)

你可以做的是:

success: function (data) {
   var $listing = $("#listings_categories");

   $.each( data, function(item){
       $listing
            .append("<p>" + item.title + "</p>")
            .append("<img src='" + item.image1 + "'/>");
            // etc.
   });
}