• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

基于apicloudAJAX请求代码合集

jquery 搞代码 4年前 (2021-12-27) 33次浏览 已收录 0个评论

下面小编就为大家带来一篇基于apicloudAJAX请求代码合集。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

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', //该参数若不传,则默认为json data: { 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:'f<b style="color:transparent">来源gao@dai!ma.com搞$代^码网</b>ilepath' // 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-600'} } },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-600'} } },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读取接口数据】

   <title>test</title> <button>点我获取数据</button>

以上就是基于apicloudAJAX请求代码合集的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:基于apicloudAJAX请求代码合集

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址