yank yank - 1 year ago 86
Javascript Question

How to display json_encode value in html?

I am very new to ajax and json stuff. Here is jQuery:

data = JSON.parse(data);
$( '#detail' ).val(data.a);
$( '#sector' ).val(data.b);
$( '#unit' ).val(data.c);


'a' => $project_code,
'b' => $b,
'c' => $c

I want to display value of

$a, $b and $c

In div

enter image description here

detail, sector and unit

But I cannot display them.

Answer Source

You are missing printing like echo. Your PHP should be:

echo json_encode(array(
    'a' => $a,
    'b' => $b,
    'c' => $c


    {  data = JSON.parse(data); 
      $( '#detail' ).html(data.a);
      $( '#sector' ).html(data.b);
      $( '#unit' ).html(data.c);  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download