|
- var model = api.require('model');
- model.uploadFile({
- report: false,
- data: {
- file: {
- name: 'avatar.'+fileType,
- url: locAvatar
- }
- }
- }, function(ret, err){
- if( ret ){
- console.log( JSON.stringify( ret ));
- fnPost('user/'+userId, {
- body:JSON.stringify({
- avatar:ret,
- city:locCity,
- birthday:locBirthday,
- gender:locGender,
- _method:'PUT'
- })
- }, 'application/json', true, true, function(ret, err) {
- if (err) {
- api.alert({
- title: '提示',
- msg: JSON.stringify(err)
- });
- } else {
- console.log(JSON.stringify(ret));
- }
- });
- }else{
- console.log( JSON.stringify( err ) );
- }
- });
- function fnPost(path, data, contentType, isLogin, isPut, callback) {
- var headers = {
- "X-APICloud-AppId": appid,
- "X-APICloud-AppKey": appKey
- };
- if (contentType) {
- headers["Content-Type"] = contentType
- }
- var accessToken = $api.getStorage('accessToken');
- if(accessToken){
- headers["authorization"] = accessToken;
- }
- if (isLogin) {
- if (!accessToken) {
- api.openWin({
- name: 'login',
- url: 'widget://html/login.html'
- });
- return;
- }
- }
- api.showProgress({
- title: '拼命加载中...',
- modal: false
- });
- // alert(JSON.stringify(headers))
- console.log('Path:'+'https://d.apicloud.com/mcm/api/' + path + 'Data:' + JSON.stringify(data));
- api.ajax({
- url: 'https://d.apicloud.com/mcm/api/' + path,
- method: isPut ? 'put' : 'post',
- timeout: 60,
- dataType: 'json',
- returnAll: false,
- headers: headers,
- cache: false,
- data: data
- }, function(ret, err) {
- api.refreshHeaderLoadDone();
- api.hideProgress();
- callback(ret, err);
- });
- };
复制代码
这种方法可以。 |
|