March 16, 2012

to get the values from php to jquery using JSON

Question by user1221098

I am very new to these things .. It might be the easiet question but sitll…..I have to get the date from my mysql database using php and from there to jquery file using JSON to make it work with my jquery plugin. I have put the values in array and used `

    $tDate['year']= 2012
    $tDate['month']=03
    $tDate['day']=06


echo json_encode($tDate);

`
and in my jquery I need to read all these data how do I do it .. have been looking into quite a few websites but have no idea

Answer by Starx

Use $.getjSON(), if the requirement is only to get the json data.

$.getJSON('your.php', function(data) {

  $.each(data, function(key, val) {
    alert(val);
  });

});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!