serialize()serializeArray()param()
<script type="text/javascript" src="js/jquery-3.2.1.js" ></script><script>$(function(){$("#btn").click(function(){//console.log($("#form1").serializeArray());console.log($(":text,select,:checked").serializeArray());//console.log("hello world");})})</script>
JSON.stringify()JSON.parse()json_encode()json_decode()serialize()
unserialize()
json_file_put() 保存为json文件json_file_get() 从json文件取出json字符串或php数组array_file_put() 将数组保存到文件array_file_get() 从文件读取数组fieldIndex() 以指定字段为索引返回数据库所取的数据数组,与js的hasOwnProperty()配合使用V() 根据文件最后修改时间输出带版本号src,用于强制更新缓存
</script>var jsonInfo = <{:json_encode($info,JSON_UNESCAPED_UNICODE)}>;var jsonValue = <{:json_file_get("/base_json/curd.json")}>;</script><script charset="UTF-8" src="<{:V('/layui/layui.js')}>"></script>
<?php
$arr = json_file_get("/base_json/curd.json",true);/**
* 保存为json文件
* @param [type] $arr json的数据源
* @param [type] $filePath 文件路径
* @param string $location 保存位置
*/
function json_file_put($arr,$filePath,$location='pub'){
$location = strtolower($location);
switch ($location) {
case 'res':
$dir = RES;
break;
case 'pub':
default:
$dir = PUB;
break;
}
$filePath = '/'.ltrim($filePath,'/');
$json = json_encode($arr,JSON_UNESCAPED_UNICODE);
return file_put_contents($dir.$filePath, $json);
} //保存为json文件/**
* 从json文件取出数据
* @param string $filePath 文件路径
* @param string $jsonDecode 是否解码
* @param string $location 保存位置
* @return mixed 解码为真返回php数组,为假返回json字符串
*/
function json_file_get($filePath,$jsonDecode=false,$location='pub'){
$location = strtolower($location);
switch ($location) {
case 'res':
$dir = RES;
break;
case 'pub':
default:
$dir = PUB;
break;
}
$filePath = '/'.ltrim($filePath,'/');
$content = file_get_contents($dir.$filePath);
if($jsonDecode===true){
$content = json_decode($content,true);
};
return $content;
} //从json文件取出数据