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:'filepath'
// filepath  ios  Android           
}
},function(ret,err){
if (ret) {
api.alert({msg:JSON.stringify(ret)});
} else {
api.alert({msg:JSON.stringify(err)});
};
});

POST 요청-Multiport-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:'    :
' + 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>
이상 의 apicloudAJAX 요청 코드 모음 집 은 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저희 도 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기