下面我就为大家带来一篇基于apicloudAJAX请求代码合集。现在就分享给大家,也给大家做个参考。
get请求代码:
1 2 3 4 5 6 7 8 9 | api.ajax({
url:'http:
}, function (ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});
|
登录后复制
POST请求-Form表单提交:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | api.ajax({
url: 'http:
method: 'post',
dataType: 'text',
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请求-单个/多个文件,文件组上传:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | api.ajax({
url: 'http:
method: 'post',
data: {
files:{myfile: 'filepath'}
}
}, function (ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});
|
登录后复制
POST请求-提交二进制流:
1 2 3 4 5 6 7 8 9 10 11 12 13 | api.ajax({
url: 'http:
method: 'post',
data: {
body:'textbits'
}
}, function (ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});
|
登录后复制
POST请求-提交文件流:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | api.ajax({
url: 'http:
method: 'post',
data: {
stream:'filepath'
}
}, function (ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});
|
登录后复制
POST请求-Multipart-Data,文件和文本字段一起提交:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | api.ajax({
url: 'http:
method: 'post',
data: {
values:{name: 'devlp', password: '123456'},
files:{file: 'fs:
}
}, function (ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});
|
登录后复制
POST请求-显示上传进度:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | api.ajax({
url: 'http:
method: 'post',
report: true,
data: {
values:{name: 'devlp', password: '123456'},
files:{file: 'fs:
}
}, function (ret,err){
if (ret){
if (0 == ret.status){
} else {
api.alert({msg:'上传成功:\n' + JSON.stringify(ret)});
}
} else {
api.alert({msg:JSON.stringify(err)});
}
});
|
登录后复制
【端API使用api.ajax读取接口数据】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!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({
url:'http:
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>
|
登录后复制
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
如何利用jquery ajax实现文件上传功能
关于jQuery ajax - ajax() 的使用方法
Yii+upload实现AJAX上传图片的方法
以上是基于apicloudAJAX请求代码合集(绝对详细)的详细内容。更多信息请关注PHP中文网其他相关文章!