一开始用的each循环,android可以,执行多次wx.uploadImage,但在IOS中却只执行最后一个上传方法
也许因为wx.uploadImage 有执行成功失败的回调函数
这里用递归解决`
function upload() {
wx.uploadImage({
localId : localIds[i],
success : function(res) {
serverIds.push(res.serverId);
i++;
if (i < length) {
upload();
} else {
alert("serverIds" + serverIds);
$.ajax({
type : "post",
url : "upload.do",
data : {
"serverIds" : serverIds,
"name" : name,
"tel" : tel,
"email" : email
},
success : function() {
alert("提交成功");
},
fail : function() {
alert("服务器异常");
}
});
}
},
fail : function() {
alert("upload fail please wait a moment and try again");
}
});
}`