用微信上傳圖檔,遇到個怪怪的問題。
要上傳四張圖檔。在安卓手機的微信那裡4張上傳成功;在蘋果手機那裡隻能上傳成功最後一張。代碼如下:
// 上傳的函數。根據id,上傳相應的圖檔
function uploadImage(id) {
wx.uploadImage({
localId: images[id],
isShowProgressTips: ,
success: function(res) {
idImages[id] = res.serverId;
alert('the picture: ' + id);
alert('the ' + Object.keys(idImages).length + ': ' + idImages[id]);
if (id == 'Head' && Object.keys(idImages).length >= ) {
var data = {
'id_front': idImages['IdFront'],
'id_back': idImages['IdBack'],
'id_student': idImages['IdStudent'],
'head': idImages['Head']
};
$.post('{{ url_for('tutor.qualification') }}', data, function(data) {
if ('errcode' in data) {
upload.text('失敗。請稍後重試');
} else {
alert('上傳成功!我們将在24小時内進行稽核。稽核結果請進入“個人中心-消息”檢視。');
location.assign('{{ url_for('common.index_tutor') }}');
}
}, 'json');
}
}
});
}
通過
uploadImage('IdFront');
uploadImage('IdBack');
uploadImage('IdStudent');
uploadImage('Head');
進行上傳。
而後,根據 alert 提示的資訊,覺得在iOS上的微信不能這樣上傳好幾張圖檔。
是以,就改成如下樣子,一張上傳完後到下一張:
uploadImages();
function uploadImages() {
wx.uploadImage({
localId: images['IdFront'],
isShowProgressTips: ,
success: function(res) {
idImages['IdFront'] = res.serverId;
wx.uploadImage({
localId: images['IdBack'],
isShowProgressTips: ,
success: function(res) {
idImages['IdBack'] = res.serverId;
wx.uploadImage({
localId: images['IdStudent'],
isShowProgressTips: ,
success: function(res) {
idImages['IdStudent'] = res.serverId;
wx.uploadImage({
localId: images['Head'],
isShowProgressTips: ,
success: function(res) {
idImages['Head'] = res.serverId;
if (Object.keys(idImages).length >= ) {
var data = {
'id_front': idImages['IdFront'],
'id_back': idImages['IdBack'],
'id_student': idImages['IdStudent'],
'head': idImages['Head']
};
$.post('{{ url_for('tutor.qualification') }}', data, function (data) {
if ('errcode' in data) {
upload.text('失敗。請稍後重試');
} else {
alert('上傳成功!我們将在24小時内進行稽核。稽核結果請進入“個人中心-消息”檢視。');
location.assign('{{ url_for('common.index_tutor') }}');
}
}, 'json');
}
}
})
}
})
}
})
}
})
}
隻是實作了功能,沒有寫成遞歸的形式。
至此,問題已解決。