Reputation: 1008
i have mysql database for i fetch information using json for example:
$sql ="SELECT * FROM parent WHERE id = '$name'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$abc=$row[id];
}
echo json_encode($abc)
Now how can i display this json encoded element in my main html file using jquery? what i want to do is based on this fetched element i want to do some if else operation.
for example:
if(value of row[id](should be achieved using jquery) ==null)
{}
else
{}
I am looking for something like $(xxxx).somefunction() Thanks in advance.
Upvotes: 0
Views: 92
Reputation: 5860
You could use jQuery to convert the JSON into a JavaScript object and then add the properties of the object into your html.
jQuery.parseJSON( json )
Add the JSON from the database to your webpage through:
echo "var myJson = ".json_encode($abc);
Then use jQuery to parse the JSON through:
myObject = jQuery.parseJSON(myJson);
alert(myObject.id);
Upvotes: 1
Reputation: 2959
You can create a javascript var:
echo('var test = ' . json_encode($abc));
Now you can acces the var "test" with javascript.
Upvotes: 1