PHP返回 json_encode JQ JSON 接受 求高手

rui20100122 2012-03-26 10:23:33
PHP代码:
$group_rs=select_spell("article_widget_article_channel","*","site_id=$zd",'nodepath');

if(!empty($group_rs))
{
foreach($group_rs as $i=>$rs)
{
$ary[$i] = array("id" =>$rs['id'],"nodepath" =>$rs['nodepath']);
}
}
echo json_encode($ary);

页面显示:
[{"id":"1","nodepath":"001"},{"id":"2","nodepath":"001001"},{"id":"3","nodepath":"002"},{"id":"4","nodepath":"002001"},{"id":"7","nodepath":"004"},{"id":"8","nodepath":"004001"},{"id":"9","nodepath":"004002"}]

JS 代码:
function getleft(id){
zz="zid="+id;
jQuery.ajax({
type:"get",
url:"manage/tz_left.php",
data:zz,
dataType:"json",
beforeSend: function(){
//
},
success:function(msg){
jQuery.each(msg, function(i,n){
alert(n.id);
alert(n.nodepath);
});
} ,
complete: function(XMLHttpRequest, textStatus){
alert(XMLHttpRequest);
alert(textStatus);
}
});
}

然后报错了
小弟刚学PHP 跟JQ 不知道这个哪里错了?
另外
类似这种直接赋值的写法
/*$id=array();
$id[0]["id"]='1';
$id[0]["name"]='张三';
$id[0]["type"]='111111';
$id[1]["id"]='2';
$id[1]["name"]='李四';
$id[1]["type"]='2222';
echo json_encode($id);*/
是可以接受到的
...全文
190 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
freedom_gooboy 2012-03-26
  • 打赏
  • 举报
回复
success:function(msg){
jQuery.each(msg, function(i,n){
alert(n.id); //这个地方改为 alert(n[0].id); 试下
alert(n.nodepath); //这个地方改为 alert(n[0].nodepath); 或者alert(n[i].nodepath);

});
} ,
Practical instruction on using JavaScript Object Notation (JSON) with MySQL This hands-on guide teaches, step by step, how to use JavaScript Object Notation (JSON) with MySQL. Written by a MySQL Community Manager for Oracle, MySQL and JSON: A Practical Programming Guide shows how to quickly get started using JSON with MySQL and clearly explains the latest tools and functions. All content is based on the author’s years of interaction with MySQL professionals. Throughout, real-world examples and sample code guide you through the syntax and application of each method. You will get in-depth coverage of programming with the MySQL Document Store. •See how JavaScript Object Notation (JSON) works with MySQL •Use JSON as string data and JSON as a data type •Find the path, load data, and handle searches with REGEX •Work with JSON and non-JSON output •Build virtual generated columns and stored generated columns •Generate complex geometries using GeoJSON •Convert and manage data with JSON functions •Access JSON data, collections, and tables through MySQL Document Store 1 Introduction JSON MySQL The Example Database How to Use This Book 2 JSON as String Data vs. JSON as a Data Type JSON String Data The JSON Data Type 3 Finding the Path Examining the world_x Data Seeing the Keys Path Digging Deeper 4 Finding and Getting Data All Keys Searching for a Key Searching for a Path Searching for a Value 5 Changing Data Using Arrays Appending Arrays Inserting into an Array Using TRUNCATE Before Adding New Data Using JSON_INSERT Using JSON_REPLACE JSON_REMOVE JSON_SET JSON_UNQUOTE The Three JSON_MERGE Functions JSON_MERGE JSON_MERGE_PRESERVE JSON_DEPTH JSON_LENGTH JSON_TYPE JSON_VALID JSON_STORAGE_SIZE JSON_STORAGE_FREE 6 JSON and Non-JSON Output JSON-Formatted Data JSON_OBJECT JSON_ARRAY Casting Non-JSON Output Missing Data Nested Data 7 Generated Columns Using Generated Columns Columns Generated from JSON Generated Columns: Common Errors 8 GeoJSON ST_GeomFromGeoJSON ST_AsGeoJSON 9 PHP’s JSON Functions JSON_DECODE JSON_ENCODE 10 Loading JSON Data From Download to Database Step 1: Examine the Data Step 2: Create the Table Step 3: Load the Data Using a Wrapper Step 4: Double-Check the Data jq: JSON CLI Parser With No Arguments Select Certain Fields The Restaurant Collection 11 The MySQL Document Store The X DevAPI mysqlsh Connections Session Types Collections and Documents CRUD: Create, Replace, Update, Delete Filtering Find Sorting Binding Indexing Collections Dropping a Collection 12 Programming with the MySQL Document Store Programming Examples Python Example Node.JS Example PHP Example Traditional SQL vs. MySQL Document Store The MySQL Shell and JavaScript Relational Tables Both Relational and Document Document as Relational A Additional Resources Index

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧