国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > AJAX > 正文

基于apicloudAJAX請求代碼合集

2024-09-01 08:27:06
字體:
來源:轉載
供稿:網友

get請求代碼:

api.ajax({url:'http://m.weather.com.cn/data/101010100.html' //天氣預報網站的WebService接口},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-Form表單提交:

api.ajax({url: 'http://www.xxx.com/path/form',method: 'post',dataType: 'text', //該參數若不傳,則默認為jsondata: {values:{name: 'devlp', password: '123456'} //鍵值對}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-單個/多個文件,文件組上傳:

api.ajax({url: 'http://www.xxx.com/path/upLoad',method: 'post',data: {files:{myfile: 'filepath'}// filepath來自ios或者Android的文件系統中的任意文件。可設置多個文件,甚至是文件數組,如files:{myfile: 'filepath', myfile1: 'filepath1'}或者files:{'myfile[]': ['filepath', 'filepath1']}等}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-提交二進制流:

api.ajax({url: 'http://www.xxx.com/path/body',method: 'post',data: {body:'textbits'}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-提交文件流:

api.ajax({url: 'http://www.xxx.com/path/body',method: 'post',data: {stream:'filepath'// filepath來自ios或者Android的文件系統中的任意文件}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-Multipart-Data,文件和文本字段一起提交:

api.ajax({url: 'http://www.xxx.com/path/multipart',method: 'post',data: {values:{name: 'devlp', password: '123456'},files:{file: 'fs://test.png'}}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST請求-顯示上傳進度:

api.ajax({url: 'http://www.xxx.com/path/multipart',method: 'post',report: true,data: {values:{name: 'devlp', password: '123456'},files:{file: 'fs://test.png'}}},function(ret,err){if(ret){if(0 == ret.status){//loading('進度:' + ret.progress);}else{api.alert({msg:'上傳成功:/n' + JSON.stringify(ret)});}}else{api.alert({msg:JSON.stringify(err)});}});

【端API使用api.ajax讀取接口數據】

<!DOCTYPE HTML><html><head><meta charset="utf-8"><meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/><title>test</title></head><body><button onclick="showPersonInfo()">點我獲取數據</button></body><script type="text/javascript" src="../script/api.js"></script><script>function showPersonInfo(){api.showProgress();//顯示加載進度框//使用api.ajax請求數據,具體使用方法和參數請看官方文檔,這里使用get方法演示api.ajax({url:'http://192.168.0.10/get.php',//如果地址訪問不到會請求出錯,請填寫自己的接口地址method:'get',cache:'false',timeout:30,dataTpye:'json',},function(ret,err){api.hideProgress();//隱藏加載進度框if(ret){for(var i=0;i<ret.length;i++){var html='<br>'+'ID:'+ret[i].id+'<br>'+'姓名:'+ret[i].name+'<br>'+'性別:'+ret[i].sex+'<br>'+'年齡'+ret[i].age; document.write(html);}}else{api.alert({msg:('錯誤碼:'+err.code+';錯誤信息:'+err.msg+'網絡狀態碼:'+err.statusCode)});}});}</script></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 株洲县| 若尔盖县| 巴中市| 砚山县| 秦皇岛市| 崇明县| 额尔古纳市| 饶平县| 陆良县| 克拉玛依市| 云龙县| 建昌县| 靖安县| 安乡县| 当阳市| 梁平县| 丰顺县| 泉州市| 济阳县| 鹤峰县| 民权县| 遂川县| 新晃| 石柱| 东源县| 孟村| 济阳县| 卫辉市| 永清县| 西林县| 泾川县| 彩票| 莱西市| 永康市| 临邑县| 闸北区| 岐山县| 德化县| 平顶山市| 珲春市| 启东市|