Ajaxupload.js Upload Error

Source: Internet
Author: User

I believe that everyone in the work often use the file upload operation, because I am engaged in front-end, so here is mainly about Ajax in the front-end operation. Code I omitted more, directly take JS there

$.ajaxfileupload ({                        URL: ' www.coding/mobi/file/uploadSingleFile.html ',//Handle picture script                        Secureuri:false,                        Fileelementid: ' Image2 ',//file control ID. is input type= "file" id= "Image2"                        dataType: ' json ',                        success:function (data, status) {                            console.log (data);                        },                        error:function (data, status, E) {                            alert (e);                        }                   })

According to the tutorial, it is no problem to upload words like this, but it has been an error. Newspaper is what wrong a bit forget, sorry, because after a long time to remember to fill back this article, but to modify its source code, the error can be solved

It's the last paragraph of the source code.

Uploadhttpdata:function (r, type) {        var data =!type;        data = Type = = "xml" | | Data? R.responsexml:r.responsetext;        If the type is ' script ', eval it in global context        if (type = = "Script")            jquery.globaleval (data);        Get the JavaScript object, if JSON is used.        if (type = = "json")            eval ("data =" + data);        Evaluate scripts within HTML        if (type = = "html")            jQuery ("<div>"). HTML (data). Evalscripts ();//alert ($ (' param ', data). each (function () {Alert ($ (this). attr (' value '));}));        return data;    }

Change this paragraph to this

Uploadhttpdata:function (r, type) {        var data =!type;        data = Type = = "xml" | | Data? R.responsexml:r.responsetext;        If the type is ' script ', eval it in global context        if (type = = "Script")            jquery.globaleval (data);        Get the JavaScript object, if JSON is used.        if (type = = "json") {            //  because the JSON data is wrapped by the <pre> tag, so there is a problem, now add the following code,            //  update by Hzy            var reg =/& Lt;pre.+?> (. +) <\/pre>/g;              var result = Data.match (reg);             result = regexp.$1;            Update end            data = $.parsejson (result);            eval ("data =" + data);        Evaluate scripts within HTML    }        if (type = = "html")            jQuery ("<div>"). HTML (data). Evalscripts (); /alert ($ (' param ', data). each (function () {alert ("(This). attr (' value ')");});        return data;    }

So you can use it normally.

Ajaxupload.js Upload Error

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.