mapping ajax data to jquery -


i having json data as

data.json file

 {    "response":[         {"id":1,"name":"crime","rel":4},         {"id":2,"name":"murder","rel":5},         {"id":3,"name":"horror","rel":6},         {"id":4,"name":"comedy","rel":1},        {"id":5,"name":"novel","rel":2,}      ]   } 

and ajax call is..

 document.onreadystatechange = function () {    if (document.readystate == "interactive") {       $.ajax({            url: "data.json",            type: "get",            datatype: "json",          success: function (response) {            "use strict";             main(response);           }   });  } } 

and want rel attribute of each item trying jquery mapping

    $.fn.tagcloud = function(options) {         var opts = $.extend({}, $.fn.tagcloud.defaults, options);       var tagweights = this.map(function(){       return $(this).attr("rel");     }); 

how can response above function , getting tagweights empty how can retreive tag weights , trying make array

 tagweights = jquery.makearray(tagweights).sort(compareweights); 

so how can attribute "rel" data

problem here using json not xml or dom. avoid using attr() of jquery function.

you can try inside main function.

var tagweights = response.map(function(item){      return item.rel;  });  tagweights.sort(compareweights); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -