我对这些东西很新..它可能是一个简单的问题,但是sitll .....我必须使用php从我的mysql数据库获取日期,并从那里使用JSON使jquery文件使其与我的jquery插件。我已将值放在数组中并使用`
$tDate['year']= 2012
$tDate['month']=03
$tDate['day']=06
echo json_encode($tDate);
` 在我的jquery中,我需要阅读所有这些数据,我该怎么做..已经在调查了很多网站但不知道
答案 0 :(得分:3)
如果要求只是获取json数据,请使用$.getjSON()
。
$.getJSON('your.php', function(data) {
$.each(data, function(key, val) {
alert(val);
});
});
答案 1 :(得分:1)
在你的javascript中:
$.get('/uri/to/script.php', function(data) {
console.log(data);
}, 'json');
答案 2 :(得分: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
});
答案 3 :(得分:0)
尝试Jquery $.getJson()
的getJson方法syntaxk就像这样
jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] )
例如:
$.getJSON('Url of PHP', function(response) {
$.each(resopnse, function(key, val) {
//do some thing with Val
});
});