<script src= "/scripts/ajaxfileupload.js" ></script><script src= "/scripts/jquery2.1.1.min.js" > </script><script type= "Text/javascript" > $ (function () {$ (": Button"). Click (function () {if ("#fileLoad"). Val (). length > 0< span>) {ajaxfileupload (); } else {alert ("Please select File! ");})}) function Ajaxfileupload () {$.ajaxfileupload ({url: '/api/poi/picture-upload '),//server-side request address for file upload type: ' Post ' span>, Secureuri:false,//general set to False Fileelementid: ' Fileload ',//File upload Space id attribute <input type= "file" id= "Fileload" name= "File"/> dataType: ' json ',//return value type Success:function (data, status)///Server Success Response handler {$ ("#img1"). attr ("src" , Data.data); if (typeof (Data.error)! = ' undefined ' ) {if (Data.error! = ' ) {console.log (data.error);} else {cons Ole.log (DATA.MSG); }}, Error:function (data, status, E)//server response failure handler {console.log (data);}}) return False ;} </script>
Ajaxfileupload the upload succeeds but executes error: there is more information in the returned JSON data causing
Add this piece to the Ajaxfileupload.js:
if (type = = "json" ) var start = Data.indexof (' {'); var end = Data.indexof ('} ') +1; data = data.substring (start,end); eval ("data =" + data);
Ajaxfileupload reported this error jquery.handleerror is not a function: version issue.
Add this piece to the Ajaxfileupload.js:
Handleerror:function(S, xhr, status, E) { //If A local callback is specified, fire it If (s.e Rror) { s.error.call (S.context | | s, XHR, status, E); } Fire the global callback if (s.global) { (s.context? JQuery (S.context): jquery.event). Trigger ("Ajax Error ", [XHR, S, E]);} }
Ajax uploading files and handling common problems in use