一、作用
用于ajax調(diào)用數(shù)據(jù)、手機(jī)端調(diào)用接口(此功能只具有讀的操作)
二、語法(請將下面的“& param”中的空格去掉)
{SITE_URL}index.php?c=api&m=data2&auth={md5(SYS_KEY)}&format=參數(shù)值& param=list標(biāo)簽語法
三、參數(shù)介紹(紅色表示必填參數(shù),藍(lán)色表示系統(tǒng)默認(rèn)參數(shù))
參數(shù) | 介紹 |
---|---|
auth | {md5(SYS_KEY)} |
format | json:返回json數(shù)據(jù)、jsonp:返回jsonp格式數(shù)據(jù);xml:返回xml數(shù)據(jù) |
param | 此值用于填寫list標(biāo)簽語法格式,即返回當(dāng)前l(fā)ist標(biāo)簽的查詢值 |
四、返回變量
變量 | 參數(shù) |
---|---|
{$返回變量.error} | 當(dāng)存在error值時(shí),表示此請求有錯(cuò)誤 |
{$返回變量.sql} | 顯示當(dāng)前查詢的sql語句 |
{$返回值.return} | 當(dāng)前查詢的返回結(jié)果集 |
五、相關(guān)例子
1、用jsonp方式調(diào)用新聞模塊的10條最新數(shù)據(jù)(請將下面的“& param”中的空格去掉)
var url = '{SITE_URL}index.php?c=api&m=data2&format=jsonp&auth={md5(SYS_KEY)}& param=list action=module module=news order=updatetime num=10'; $.ajax({ type:'get', url:url, dataType:'jsonp', jsonp:'callback', async: false, success:function(data){ if (data.error) { alert("錯(cuò)誤:"+data.error); } else { var id; var row = data.return; for (id in row) { // 這里是循環(huán)顯示新聞了 alert("標(biāo)題:"+row[id]['title']+" URL:"+row[id]['url']); } } }, error: function(HttpRequest, ajaxOptions, thrownError) { alert(HttpRequest.responseText); } });
2、用jsonp瀑布流的方式調(diào)用新聞模塊的數(shù)據(jù),每頁顯示10條(請將下面的“& param”中的空格去掉)
①、JS部分
var page = 0; // 頁數(shù)開始 var pagesize = 10; // 每頁顯示數(shù)量 function load_more_data() { var url = ''; url+= '{SITE_URL}index.php?c=api&m=data2&format=jsonp&auth={md5(SYS_KEY)}& param=';//請將“& param”中的空格去掉 url+= 'list action=module module=news order=updatetime num='+(page * pagesize)+','+pagesize;// 這是分頁查詢的list標(biāo)簽 $.ajax({ type:'get', url:url, dataType:'jsonp', jsonp:'callback', async: false, success:function(data){ if (data.error) { alert("錯(cuò)誤:"+data.error); } else { var id; var row = data.return; var html = ''; // 開始組裝查詢結(jié)果 for (id in row) { html+= '<p>'+row[id]['title']+'</p>'; } $('#dr_ajax_result').append(html); // 將結(jié)果追加到顯示區(qū)域 } }, error: function(HttpRequest, ajaxOptions, thrownError) { alert(HttpRequest.responseText); } }); page++; } $(function(){ load_more_data(); // 第一次加載數(shù)據(jù) });
②、HTML部分
<div id="dr_ajax_result"> </div> <a href="javascript:load_more_data();">單擊加載</a>
在線體驗(yàn):http://223987.com/v3doc/index.php?c=doc&m=log3
文檔最后更新時(shí)間:2017-05-05 10:00:18