的Javascript:我的Ajax調用不工作 - 嘗試通過AJAX PHP和MySQL JSON填充jstree
$('#jstree1').jstree({ 'core' : {
// I usually configure the plugin that handles the data first
// This example uses JSON as it is most common
"json_data" : {
// This tree is ajax enabled - as this is most common, and maybe a bit more complex
// All the options are almost the same as jQuery's AJAX (read the docs)
"ajax" : {
// the URL to fetch the data
"type" : "POST",
"url" : "./ajax/get_page_data.php",
"dataType": "JSON",
"contentType": "application/json;",
"data":
"d_id="+<?=$DOC['d_id']?>,
"success" : function (data) {
// 'data' is a JSON object which we can access directly.
// Evaluate the data.success member and do something appropriate...
alert(data);
if (data.success == true){
$('#section1').html(data);
} else {
$('#section2').html(data);
}
},
"error": function (error) {
alert('error; ' + eval(error));
}
}
}
} });
及以下爲get_page_data.php它不是相當的工作我的輸出:
[{"id":"ajson12","parent":"#","text":"Welcome"},{"id":"ajson13","parent":"#","text":"Getting to Us"},{"id":"ajson14","parent":"13","text":"About Us"},{"id":"ajson15","parent":"13","text":"Visit Us"},{"id":"ajson16","parent":"13","text":"Bus Routes"},{"id":"ajson17","parent":"#","text":"Choices"},{"id":"ajson18","parent":"#","text":"Guidance"},{"id":"ajson19","parent":"#","text":"Facilities"}]
在測試一些JSON數據手動下面將工作:
$('#jstree1').jstree({ 'core' : {
'data' : [{"id":"ajson12","parent":"#","text":"Welcome"},{"id":"ajson13","parent":"#","text":"Getting to Us"},{"id":"ajson14","parent":"13","text":"About Us"},{"id":"ajson15","parent":"13","text":"Visit Us"},{"id":"ajson16","parent":"13","text":"Bus Routes"},{"id":"ajson17","parent":"#","text":"Choices"},{"id":"ajson18","parent":"#","text":"Guidance"},{"id":"ajson19","parent":"#","text":"Facilities"}]
} });
我到處都找過網,不能找到一個完美的例子,通過使用PHP array/mysql提供並輸出爲Json的ajax來填充jsTree。
您好,我刪除了您的帖子中的鏈接,因爲它很脆弱,請立即將您的mysql *函數更改爲PDO(或)Mysqli函數。 –
[PHP 4?它的支持已經在2008年停止。](http://www.php.net/archive/2008.php#id2008-08-07-1) – Gumbo
對不起,它更像是PHP 5.2或者我只是認爲它是4. –