How to parse Json to a JQuery function and get the values inside the function -
i trying create plugin "bg-rotator" takes parameters in json format:
$('.selector').bg_rotator({ 'duration':500, 'delay':5000 });
then in jquery function trying json object , split values:
(function( $ ){ $.fn.bg_rotator = function(jsonobj) { var cn = $(this).attr('class'); //get class name var obj = json.parse(jsonobj); //get json object var duration = obj.duration; var delay = obj.delay; }; })( jquery );
this giving me errors , can't find way parse , json values. ideas? thanks
this worked:
(function( $ ){ $.fn.bg_rotator = function(jsonobj) { var cn = $(this).attr('class'); //get class name var duration = jsonobj.duration; //get json object var delay = jsonobj.delay; }; })( jquery );
json javascript object notation. idea regular javascript objects, can use them regular javascript objects. don't need parse objects unless have been stringified. in case you're passing regular object, access object's properties, no parsing necessary.
Comments
Post a Comment