多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 仅限zzzphp版本 | 字段 | 名称 | 描述 | | --- | --- | --- | | table | 数据表 | 从那个表调用数据 | | col | 数据字段 | 调用哪些字段 | | where | 条件 | 查询条件 | | num | 数量 | 查询数量 | | page | 页码 | 分页 | | order | 排序 | | jquery版本 ~~~ <script type="text/javascript"> $(function () { $.ajax({ type:"POST", url:"/form/?getjson", dataType:"json", data:{"table":"content","col":"cid,c_title,c_content","where":"c_sid=6","page":1,"order":'cid desc','num':10}, timeout: 1000, cache: false, beforeSend: LoadFunction, //加载执行方法 error: erryFunction, //错误执行方法 success: succFunction //成功执行方法 }); function LoadFunction() { $("#list").html('加载中...'); } function erryFunction() { alert("error"); } function succFunction(data) { $("#list").html(''); var json = eval(data); //数组 $.each(json, function (index, item) { var title = json[index].c_title; var id = json[index].cid; var content = json[index].c_content; $("#list").html($("#list").html() + "<br>" + title + " - " + id + " - " +content+ "<br/>"); }); } }); </script> ~~~ js版本 ~~~ <script type="text/javascript"> //调用ajax函数 window.onload = function() { ajax({ url: "/form/?getjson", type: 'POST', dataType: 'json', data: { "table": "content", "col": "cid,c_title,c_content", "where": "c_sid=6", "page": 1, "order": 'cid desc', 'num': 10 }, success: function(json, xml) { for (var i = 0, l = json.length; i < l; i++) { var content = document.getElementById("list").innerHTML + '<br>'; document.getElementById("list").innerHTML = content + json[i].cid + " " + json[i].c_title; } }, error: function(status) { alert(2222); } }); } //创建ajax函数 function ajax() { var ajaxData = { type: arguments[0].type || "POST", url: arguments[0].url || "", async: arguments[0].async || "true", data: arguments[0].data || null, dataType: arguments[0].dataType || "text", contentType: arguments[0].contentType || "application/x-www-form-urlencoded", beforeSend: arguments[0].beforeSend || function() {}, success: arguments[0].success || function() {}, error: arguments[0].error || function() {} } ajaxData.beforeSend() var xhr = createxmlHttpRequest(); xhr.responseType = ajaxData.dataType; xhr.open(ajaxData.type, ajaxData.url, ajaxData.async); xhr.setRequestHeader("Content-Type", ajaxData.contentType); xhr.send(convertData(ajaxData.data)); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { ajaxData.success(xhr.response) } else { ajaxData.error() } } } } function createxmlHttpRequest() { if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { return new XMLHttpRequest(); } } function convertData(data) { if (typeof data === 'object') { var convertResult = ""; for (var c in data) { convertResult += c + "=" + data[c] + "&"; } convertResult = convertResult.substring(0, convertResult.length - 1) return convertResult; } else { return data; } } </script> ~~~