笔者对JSON对象代码进行说明介绍
这里考虑都考虑的是服务器返回的是JSON形式的字符串的形式,对于利用JSONObject等插件封装的JSON对象,与此亦是大同小异,这里不再做说明,下面进行JSON对象代码说明:
10年积累的成都网站制作、做网站、外贸营销网站建设 经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作 后付款的网站建设流程,更有东城免费网站建设 让你可以放心的选择与我们合作。
>
xmlns="http://www.w3.org/1999/xhtml">
test2
/>
id="first" type="button" value=" << " /> id="previous" type="button"
value=" < " /> id="next" type="button" value=" > " /> id="last" type="button"
value=" >> " />
id="pageinfo">
id="template">
id="OrderID">
订单ID
/
id="CustomerID">
客户ID
id="EmployeeID">
雇员ID
/
id="OrderDate">
订购日期
/
id="ShippedDate">
发货日期
/
id="ShippedName">
货主名称
/
id="ShippedAddress">
货主地址
/
id="ShippedCity">
货主城市
/
id="more">
注:对于一般的js生成json对象,只需要将$.each()方法替换为for语句即可,其他不变。 对于服务器返回的JSON字符串,如果jquery异步请求将type(一般为这个配置属性)设为“json”,或者利用$.getJSON()方法获得服务器返回,那么就不需要eval()方法了。#t#
因为这时候得到的结果已经是json对象了,只需直接调用该对象即可,这里以$.getJSON方法为例说明数据处理方法:
type: "get",//使用get方法访问后台
dataType: "json",//返回json格式的数据
url: "Handler.ashx",//要访问的后台地址
data: "pageIndex=" + pageIndex,//要发送的数据
complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
success: function(msg){//msg为返回的数据,在这里做数据绑定
var data = msg.table;
$.each(data, function(i, n){
var row = $("#template").clone();
row.find("#OrderID").text(n.OrderID);
row.find("#CustomerID").text(n.CustomerID);
row.find("#EmployeeID").text(n.EmployeeID);
row.find("#OrderDate").text(ChangeDate(n.OrderDate));
if(n.RequiredDate !== undefined) row.find("#ShippedDate").text(ChangeDate(n.RequiredDate));
row.find("#ShippedName").text(n.ShipName);
row.find("#ShippedAddress").text(n.ShipAddress);
row.find("#ShippedCity").text(n.ShipCity);
row.find("#more").html(" href=OrderInfo.aspx?id=" + n.OrderID + "&pageindex="+pageIndex+"> More ");
row.attr("id","ready");//改变绑定好数据的行的id
row.appendTo("#datas");//添加到模板的容器中
});
$("[@id=ready]").show();
SetPageInfo();
}
});
}
function ChangeDate(date)
{
return date.replace("-","/").replace("-","/");
}
这里特别需要注意的是方式1中的eval()方法是动态执行其中字符串(可能是js脚本)的,这样很容易会造成系统的安全问题。所以可以采用一些规避了eval()的第三方客户端脚本库,比如JSON对象就提供了一个不超过3k的脚本库。
文章名称:笔者对JSON对象代码进行说明介绍
转载来源:http://www.ywunx.com/article/djeichc.html
基本
文件
流程
错误
SQL
调试
请求信息 : 2026-03-25 14:14:38 HTTP/1.1 GET : /article/djeichc.html 运行时间 : 0.0912s ( Load:0.0032s Init:0.0205s Exec:0.0633s Template:0.0042s ) 吞吐率 : 10.96req/s 内存开销 : 2,235.14 kb 查询信息 : 12 queries 5 writes 文件加载 : 36 缓存信息 : 0 gets 0 writes 配置加载 : 130 会话信息 : SESSION_ID=514ibi4tna34lhuc7sccekn5b6
/home/wwwroot/ywunx.com/index.php ( 1.09 KB ) /home/wwwroot/ywunx.com/ThinkPHP/ThinkPHP.php ( 4.61 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Mode/common.php ( 2.82 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Common/functions.php ( 53.56 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/App.class.php ( 13.49 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/View.class.php ( 7.59 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Conf/convention.php ( 11.15 KB ) /home/wwwroot/ywunx.com/App/Common/Conf/config.php ( 2.11 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Lang/zh-cn.php ( 2.55 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Conf/debug.php ( 1.49 KB ) /home/wwwroot/ywunx.com/App/Home/Conf/config.php ( 0.31 KB ) /home/wwwroot/ywunx.com/App/Home/Common/function.php ( 3.33 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB ) /home/wwwroot/ywunx.com/App/Home/Controller/ArticleController.class.php ( 6.02 KB ) /home/wwwroot/ywunx.com/App/Home/Controller/CommController.class.php ( 1.60 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB ) /home/wwwroot/ywunx.com/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 17.51 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB ) /home/wwwroot/ywunx.com/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
[ app_init ] --START-- Run Behavior\BuildLiteBehavior [ RunTime:0.000005s ] [ app_init ] --END-- [ RunTime:0.000023s ] [ app_begin ] --START-- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000142s ] [ app_begin ] --END-- [ RunTime:0.000154s ] [ view_parse ] --START-- [ template_filter ] --START-- Run Behavior\ContentReplaceBehavior [ RunTime:0.000037s ] [ template_filter ] --END-- [ RunTime:0.000053s ] Run Behavior\ParseTemplateBehavior [ RunTime:0.003404s ] [ view_parse ] --END-- [ RunTime:0.003422s ] [ view_filter ] --START-- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000069s ] [ view_filter ] --END-- [ RunTime:0.000078s ] [ app_end ] --START--
1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= ) [8] Undefined index: pid /home/wwwroot/ywunx.com/App/Home/Controller/ArticleController.class.php 第 47 行. [2] mkdir(): Permission denied /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 59 行. [2] mkdir(): Permission denied /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 59 行. [8] Undefined index: db_host /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Db.class.php 第 120 行. [8] Undefined index: db_port /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Db.class.php 第 121 行. [8] Undefined index: db_name /home/wwwroot/ywunx.com/ThinkPHP/Library/Think/Db.class.php 第 122 行.
0.0912s