存取范例:
post: (支持直接使用本工具页面登陆后快捷"写入/修改"数据#一次性可写入11行,同名key时自动覆盖)
$.ajax({ url:'http://shujuapi.hhsy.cc/nt_api.php', //当前网址/nt_api.php cache:false, type:'post', data:{"写入/修改的key1#不支持符号":"写入content1","(可选)zhanghao":"本站账号","(可选)mima":"本站密码", ,"(可选)写入/修改的key2":"写入content2","(可选)写入/修改的key3":",,,,,更多" } , success:function (data){ console.log(data); }, error:function(e,y){alert( JSON.stringify(e) + y);} //当错误时. e默认是object! });



get: (支持url的get)
$.ajax({ url:'http://shujuapi.hhsy.cc/nt_api.php', //当前网址/nt_api.php cache:false, type:'post', data:{"(可选)zhanghao":"本站账号","(可选)mima":"本站密码","(可选)type":"返回的类型"}, success:function (data){ console.log(data); }, error:function(e,y){alert( JSON.stringify(e) + y);} //当错误时. e默认是object! });

====范例1--php读取api返回的json类型
post:
浏览器的url里直接输入: http://shujuapi.hhsy.cc/nt_api.php?datatxt=hello world&&datatxt1=hello world1 <!-- //解释:上面是get的快捷写法=>?号后面代表参数,datatxt代表第1个key,hello world代表第一个key的值.datatxt1代表第2个key,,,, //默认快捷工具已使用的的key(jinyong.txt): zhanghao,mima,is_true,id,game_data,msg //当参数type不存在或type=json时返回json,当type=var时返回js变量nt_api,当type=dom时返回<div id="nt_api">包着的字符串数据库</div> -->



get:
//============(在本地/远程服务器环境下)创建index.php文件,输入内容: <?php $json_string = file_get_contents("http://shujuapi.hhsy.cc/nt_api.php"); //$json_string = json_decode($json_string,true); // 把JSON字符串转成PHP数组 //var_dump($json_string); //输出数组 //var_dump($json_string["datatxt1"]); //输出 hello world1 echo $json_string; //输出范例: {"type":"var","datatxt":"hello world","datatxt1":"hello world1","aa":"sadw321"} ?>

====范例2--js读取api返回的var类型
post:
浏览器的url里直接输入: http://shujuapi.hhsy.cc/nt_api.php?datatxt=hello world&&datatxt1=hello world1 <!-- //解释:上面是get的快捷写法=>?号后面代表参数,datatxt代表第1个key,hello world代表第一个key的值.datatxt1代表第2个key,,,, //默认快捷工具已使用的的key(jinyong.txt): zhanghao,mima,is_true,id,game_data,msg //当参数type不存在或type=json时返回json,当type=var时返回js变量nt_api,当type=dom时返回<div id="nt_api">包着的字符串数据库</div> -->



get:
//============(在本地/远程服务器环境下)创建index.html文件,输入内容: <script src="http://shujuapi.hhsy.cc/nt_api.php?type=var"> </script> //js的调用方法: <script> console.log(nt_api["datatxt1"]); //输出范例: hello world1 </script>

====范例3--html读取api返回的dom类型
post:
浏览器的url里直接输入: http://shujuapi.hhsy.cc/nt_api.php?datatxt=hello world&&datatxt1=hello world1 <!-- //解释:上面是get的快捷写法=>?号后面代表参数,datatxt代表第1个key,hello world代表第一个key的值.datatxt1代表第2个key,,,, //默认快捷工具已使用的的key(jinyong.txt): zhanghao,mima,is_true,id,game_data,msg //当参数type不存在或type=json时返回json,当type=var时返回js变量nt_api,当type=dom时返回<div id="nt_api">包着的字符串数据库</div> -->



get:
//============(在本地/远程服务器环境下)创建index.html文件,输入内容: <script src="http://shujuapi.hhsy.cc/nt_api.php?type=dom"> </script> <!-- //html输出范例: //<div id="nt_api">{"datatxt":"hello world","datatxt1":"hello world1","type":"dom","aa":"sadw321"}</div> --> //js的调用写法: <script> var a1=document.getElementById("nt_api").innerHTML; console.log(a1); //输出范例:{"datatxt":"hello world","datatxt1":"hello world1","type":"dom","aa":"sadw321"} </script>

====范例4--php读or写api返回的json类型
post:
//============(在本地/远程服务器环境下)创建index.php文件,输入内容: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <form method="post" > <input type="text" class="short-ipt" name="dd" placeholder="输入需要写入/修改的key"/> <input type="text" class="short-ipt" name="nn" placeholder="输入需要写入/修改的内容"/> <button type="submit" class="short-btn" id="creatBtn">立即写入/修改</button> </form> <?php $dd = $_POST["dd"]; $nn = $_POST["nn"]; if ($dd){ function send_post($url, $post_data) { $postdata = http_build_query($post_data); $postdata = array( //必须是2维数组 'http' => array( 'method' => 'POST', //!!!必须用大写POST,不支持小写,也不支持GET!!! //同理对方接收也必须用$_POST 'header' => 'Content-type:application/x-www-form-urlencoded', //可省略不写 'content' => $postdata, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($postdata); //###测试必须存在! $result = file_get_contents($url, true, $context); return $result; } $post_data = array( "$dd" => "$nn" ); $a=send_post('http://shujuapi.hhsy.cc/nt_api.php', $post_data); //==========================get: (直接获取post的返回值) //echo $a; $a = json_decode($a,true); //把JSON字符串转成PHP数组(注意bug:变量名写错时无报错,也没有任何输出值!) //var_dump($a["$dd"]); } ?> <input type="text" class="short-ipt" name="dd_get" value='<?php echo $a["$dd"] ?>' placeholder="这里是读取的写法"/>

====范例5--html读or写api返回的var类型
post:
//============(在本地/远程服务器环境下)创建index.html文件,输入内容: <form id="header_form"> <div class=""> <label>key:</label> <input id="key"> </div> <div class=""> <label>value:</label> <input id="value"> </div> <button type="button" id="header_regbutton">提交</button> </form> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"> </script> //js调用的方法: <script> //=============当点击按钮时 $('#header_regbutton').click(()=>{ var a1=$('#key').val(); var zhuce_input={}; zhuce_input[a1]=$("#value").val(); zhuce_input["type"]="var"; $.ajax({ url:'http://shujuapi.hhsy.cc/nt_api.php', //当前php data:zhuce_input, success:function (data){ //=============get读取时,直接获得post的值 eval(data); console.log(nt_api[a1]); //输出范例: hello world }, error:function(e,y){alert( JSON.stringify(e) + y);} //当错误时. e默认是object! }); }) //.click(()=>{ </script>

====范例6--html读or写api返回的dom类型
post:
//============(在本地/远程服务器环境下)创建index.html文件,输入内容: <form id="header_form"> <div class=""> <label>key:</label> <input id="key"> </div> <div class=""> <label>value:</label> <input id="value"> </div> <button type="button" id="header_regbutton">提交</button> </form> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"> </script> //js调用的方法: <script> //=============当点击按钮时 $('#header_regbutton').click(()=>{ var a1=$('#key').val(); var zhuce_input={}; zhuce_input[a1]=$("#value").val(); zhuce_input["type"]="dom"; console.log(zhuce_input); fetch('http://shujuapi.hhsy.cc/nt_api.php', { method: 'POST', headers: { "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", }, body: a1+'='+$("#value").val()+'&type=dom' } ) .then(response => response.text()) .then(json => { //=============get读取时,直接获得post的值 eval(json); console.log(json); // console.log(nt_api[a1]); } ) .catch(err => console.log('读取失败', err)); //当读取失败时 //bug:没有文件时报错=> JSON中位置0处出现意外标记< }) //.click(()=>{ </script>