views:

556

answers:

2

I have a some data in JSON format(which comes from php) to be passed to a javascript function. I'm getting 'invalid property id' error when I try to do this.

Error: invalid property id Source File: http://localhost/MathVoyager/index.php/test Line: 1, Column: 15 Source Code: draw_quadratic({

Below is the js function signature(both data and options are in JSON format)

function draw_quadratic(data, options, alpha, beta)

Below is a sample function call.

`draw_quadratic({"label":"(((1)*x^((1))+(4))*((1)*x^((1))+(6))) = (0)","data":[[-8,8],[-7.5,5.25],[-7,3],[-6.5,1.25],[-6,0],[-5.5,-0.75],[-5,-1],[-4.5,-0.75],[-4,0],[-3.5,1.25],[-3,3],[-2.5,5.25],[-2,8]],"xaxis":1,"yaxis":1}, {"series":{"points":{"show":true},"lines":{"show":true}},"grid":{"hoverable":true,"clickable":true}}, 4, 8);

`

(I'm trying to plot some graph using flot js library)

Thanks in advance

A: 
mydata= JSON.parse('{"label":"(((1)*x^((1))+(4))*((1)*x^((1))+(6))) = (0)","data":[[-8,8],[-7.5,5.25],[-7,3],[-6.5,1.25],[-6,0],[-5.5,-0.75],[-5,-1],[-4.5,-0.75],[-4,0],[-3.5,1.25],[-3,3],[-2.5,5.25],[-2,8]],"xaxis":1,"yaxis":1}');

myoptions= JSON.parse('{"series":{"points":{"show":true},"lines":{"show":true}},"grid":{"hoverable":true,"clickable":true}}');

draw_quadratic( mydata,myoptions,4,8);

don't forget '' or "" when sned parameters to jsonparse it takes a string

www.JSON.org/json2.js

www.JSON.org/js.html

in php you can use .json_decode — Decodes a JSON string .json_encode — Returns the JSON representation of a value

the code i wrote works with me in chrome

m. h. ameen
A: 

Don't post links to localhost; we're not at your machine.

Garrett