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

首頁 > 開發(fā) > AJAX > 正文

基于apicloudAJAX請(qǐng)求代碼合集

2024-09-01 08:30:52
字體:
供稿:網(wǎng)友

get請(qǐng)求代碼:

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

POST請(qǐng)求-Form表單提交:

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

POST請(qǐng)求-單個(gè)/多個(gè)文件,文件組上傳:

api.ajax({url: 'http://www.xxx.com/path/upLoad',method: 'post',data: {files:{myfile: 'filepath'}// filepath來自ios或者Android的文件系統(tǒng)中的任意文件。可設(shè)置多個(gè)文件,甚至是文件數(shù)組,如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請(qǐng)求-提交二進(jìn)制流:

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請(qǐng)求-提交文件流:

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

POST請(qǐng)求-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請(qǐng)求-顯示上傳進(jìn)度:

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('進(jìn)度:' + ret.progress);}else{api.alert({msg:'上傳成功:/n' + JSON.stringify(ret)});}}else{api.alert({msg:JSON.stringify(err)});}});

【端API使用api.ajax讀取接口數(shù)據(jù)】

<!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()">點(diǎn)我獲取數(shù)據(jù)</button></body><script type="text/javascript" src="../script/api.js"></script><script>function showPersonInfo(){api.showProgress();//顯示加載進(jìn)度框//使用api.ajax請(qǐng)求數(shù)據(jù),具體使用方法和參數(shù)請(qǐng)看官方文檔,這里使用get方法演示api.ajax({url:'http://192.168.0.10/get.php',//如果地址訪問不到會(huì)請(qǐng)求出錯(cuò),請(qǐng)?zhí)顚懽约旱慕涌诘刂穖ethod:'get',cache:'false',timeout:30,dataTpye:'json',},function(ret,err){api.hideProgress();//隱藏加載進(jìn)度框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:('錯(cuò)誤碼:'+err.code+';錯(cuò)誤信息:'+err.msg+'網(wǎng)絡(luò)狀態(tài)碼:'+err.statusCode)});}});}</script></html>

以上這篇基于apicloudAJAX請(qǐng)求代碼合集就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 弥勒县| 什邡市| 东山县| 曲松县| 政和县| 同江市| 泗阳县| 祥云县| 灵丘县| 双桥区| 于田县| 饶阳县| 应用必备| 乌兰察布市| 宁阳县| 新巴尔虎右旗| 淮安市| 新余市| 南和县| 涿州市| 长岛县| 遵义县| 荆州市| 南涧| 万年县| 绵竹市| 泸西县| 瓮安县| 博野县| 苏尼特右旗| 龙川县| 湄潭县| 东明县| 合川市| 烟台市| 南投市| 通许县| 许昌市| 桃园县| 磐石市| 清远市|