Heim > Web-Frontend > js-Tutorial > Hauptteil

基于apicloudAJAX请求代码合集(绝对详细)

亚连
Freigeben: 2018-05-22 09:44:38
Original
1842 人浏览过

下面我就为大家带来一篇基于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)});
};
});
Nach dem Login kopieren

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)});
};
});
Nach dem Login kopieren

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)});
};
});
Nach dem Login kopieren

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)});
};
});
Nach dem Login kopieren

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)});
};
});
Nach dem Login kopieren

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)});
};
});
Nach dem Login kopieren

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)});
}
});
Nach dem Login kopieren

【端API使用api.ajax读取接口数据】






test

Nach dem Login kopieren

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

如何利用jquery ajax实现文件上传功能

关于jQuery ajax - ajax() 的使用方法

Yii+upload实现AJAX上传图片的方法

以上是基于apicloudAJAX请求代码合集(绝对详细)的详细内容。更多信息请关注PHP中文网其他相关文章!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!