Ajax uploading files and handling common problems in use

Source: Internet
Author: User

<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

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.