codecamp

CherryPy JSON

JSON是一种携带序列化JavaScript对象的方式,JavaScript应用程序可以对它们进行评估并将它们转换为可以在以后操作的JavaScript对象。

例如,当用户向服务器请求使用JSON格式格式化的相册对象时,服务器将返回如下输出 -

{'description': 'This is a simple demo album for you to test', 'author': ‘xyz’}

现在数据是一个JavaScript关联数组,描述字段可以通过 - 访问 -

data ['description'];


CherryPy AJAX
CherryPy 将AJAX应用于应用程序
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

CherryPy 一个工作应用程序

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }