我的Ajax调用无法正常工作-尝试通过ajax php& MySQL的JSON [英] My Ajax call isn't working - Trying to populate jstree via ajax php & mysql JSON
本文介绍了我的Ajax调用无法正常工作-尝试通过ajax php& MySQL的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JavaScript:
Javascript:
$('#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中的输出,它工作不正常:
And below is my output from get_page_data.php it's not quite working:
[{"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数据时,以下方法将起作用:
When testing some JSON data manually the below will work:
$('#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数组/以Json输出并输出的mysql通过ajax填充jsTree.
I have looked all over the net and cannot find a perfect example of populating a jsTree via ajax using PHP array / mysql fed and outputted as Json.
推荐答案
尝试一下:
$('#jstree1').jstree({
'core': {
'data': {
'url': "./ajax/get_page_data.php",
'type': 'POST',
'dataType': 'JSON',
'contentType':'application/json',
'data': function (node) {
return { 'd_id': <?=$DOC['d_id']?>};
}
}
}
});
我不确定您是否可以将自定义.success和.error函数连接到jstree.
I'm not sure that you'd be able to hookup custom .success and .error functions to jstree.
这篇关于我的Ajax调用无法正常工作-尝试通过ajax php& MySQL的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文