Micro-Letter Applet Wx.uploadfile on the Android phone the same task is working problem resolution _JAVASCRIPT

Source: Internet
Author: User

Micro-Letter Applet Wx.uploadfile on the Android phone the same task is working problem resolution

Micro-Letter Small program upload pictures, if it is more than image upload, generally is directly with a loop for wx.uploadfile

It's not going to be a problem on the computer and on the iphone.

But when you use the Android test, you'll notice that the applet prompts a same task is working

Wx.uploadfile can't be parallel because Wx.uploadfile is an asynchronous function, so there's a parallel on the Android phone at the time of the loop.

Way to solve

Do an uploaded logo, and then

Using recursive algorithm to upload

In the upload of successful callback function, direct recursion, logo satisfied directly jump out, complete all picture upload

Post Code Snippet

Upload ID var i=0//imglist for an array of paths to upload images uploadimg:function () {var that =-this if (i = = imglist.length) {//empty restore
    News = "" City = "" i=0 wait = True imglist = [] serverimg = [] Retrunlist = [] That.setdata ({
  Loding:false, SRC: [], disabled:false}) return;
   var imgcount = imglist.length; Wx.uploadfile ({url:config.serverUrl (' index.php/user/uploadtu '), Filepath:imglist[i], name: ' File ', form Data: {' user ': ' Test '}, Success:function (res) {Serverimg.push (Res.data) if (Imgcount = = Serverimg.lengt
      h) {var serverimgstr = Serverimg.join ("|") Wx.request ({url:config.serverUrl (' Index.php/user/baobeiadd '), method: ' POST ', Data:Util.json2Form ( {imglist:serverimgstr, Userid:userid, News:news, city:city, Latitude:latitud E, longitude:longitude}), header: {' Content-type ': ' Application/x-www-forM-urlencoded '}, Success:function (Res2) {if (res2.data.state = = "OK") {That.setdata ({ Loding:false, Buttxt: "Publish", Disabled:false}) Util.mesurl ("Send Cloth Success! ", ".. /index/index ")} else {util.mes (" description of at least 10 characters above oh, and pictures also to choose Oh! ")
     ")}})}else {//here directly recursively i++;
     That.uploadimg (); }, Fail:function (e) {Console.log (E) util.mes ("Picture upload failed, please republish!")

 "+ i)}}"},

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.