1

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

1

4 Answers 4

3

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

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

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

});
Sign up to request clarification or add additional context in comments.

Comments

1

In your javascript:

$.get('/uri/to/script.php', function(data) {
   console.log(data);
}, 'json');

Comments

1
$.get('/path/to/your_php_file.php', function(data){
    parseInt(data.year, 10);  // => 2012
    parseInt(data.month, 10); // => 3
    parseInt(data.day, 10);   // => 6 
});

Comments

0

try the getJson method of Jquery $.getJson()

syntaxk would be like this

jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] )

Eg:

$.getJSON('Url of PHP', function(response) {

  $.each(resopnse, function(key, val) {
//do some thing with Val
  });

});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.