我想打電話給/home/***/public_html/subdomains/busuioc/wp-content/themes/scalia/json_gallery_data.php
的json_gallery_data.php
的內容是:如何從ajax主頁wordpress中的數據庫中提取數據?
global $wpdb;
$programs = $wpdb->get_results("SELECT * FROM program_tv");
$tv=array();
foreach ($programs as $program){
$tv[]=$program->day;
}
echo json_encode($tv);
ajax的文件是:
jQuery(document).ready(function(){
loadData();
});
var loadData=function(){
jQuery.ajax({
type:"POST",
url: 'site.com/wp-content/themes/scalia/json_gallery_data.php'
}).done(function(data){
var videos=JSON.parse(data);
for(var i in videos){
alert(videos[i]);
}
});
};
將AJAX類型更改爲GET! –
'console.log(data)'看看它是否需要'JSON.parse'? –
GET site.com/wp-content/themes/scalia/json_gallery_data.php 500(內部服務器錯誤) –