SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xhr json with javascript (string instead of function)

    Hi,
    from a xhr I've got this json
    PHP Code:
    "options":
    {
    "title":"The title",
    "axes":{
            
    "xaxis":{"renderer":"$.jqplot.DateAxisRenderer","min":"Mar 26, 2013","tickInterval":"1 day"},
            
    "yaxis":{"min":0}
    },
    "series":{"color":"#F2C780","label":"users","lineWidth":4,"markerOptions":{"style":"square"}},
    "legend":{"show":true,"location":"e"}}} 
    It's all ok unless
    "renderer":"$.jqplot.DateAxisRenderer"
    from js side it's seen like a string not a function
    so
    is there a way to fix it ?
    From server side I manage the json data like
    data.options it's just an object.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by whisher View Post
    It's all ok unless
    "renderer":"$.jqplot.DateAxisRenderer"
    from js side it's seen like a string not a function
    so
    is there a way to fix it ?
    Yes - don't assign functions as JSON data - it's not designed to work like that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the point.
    I worked it out like:
    PHP Code:
    "xaxis":{"renderer":"DateAxisRenderer","min":"Mar 26, 2013","tickInterval":"1 day"},
    if(
    typeof data.options.axes.xaxis.renderer !== 'undefined'){
        
    data.options.axes.xaxis.renderer = $.jqplot[data.options.axes.xaxis.renderer];
        var 
    options data.options.options;



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •