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