display json data using AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heybobo
    New Member
    • Dec 2011
    • 2

    display json data using AJAX

    Hi,

    my aim is to display the content of my json data i receive from my php file.

    php is sending :

    PHP--->

    $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

    echo json_encode($ar r);

    <---


    AJAX--->
    ajax is receiving "data" and displaying : data = {"a":1,"b":2,"c ":3,"d":4,"e":5 }

    now, how can is display for exemple the item "c" to get "3" something like :

    alert(' a = "+..--->what must i put here<-----.);

    i tried : date[2], but it is not working ! is says : UNDEFINED


    thx for your help


    Boris
  • heybobo
    New Member
    • Dec 2011
    • 2

    #2
    SOLVED

    ------->

    solution :

    var obj = jQuery.parseJSO N(data);

    alert( obj.a);


    thx to all for you help !

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      note: associative arrays in PHP are plain objects in JS (because JS arrays are *always* numerically indexed)

      Comment

      Working...