Ajax uploading files and frequently asked questions 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 ($ ("#file1"). Val (). length > 0) {
Ajaxfileupload ();
}
else {
Alert ("Please select Picture");
}
})
})
function Ajaxfileupload () {
$.ajaxfileupload
(
{
URL: '/api/poi/picture-upload ',//server-side request address for file upload
Type: ' Post ',
Secureuri:false,//general set to False
Fileelementid: ' file1 ',//File upload Space id attribute <input type= "file" id= "file" name= "file"/>
DataType: ' json ',//return value type is generally set to JSON
Success:function (data, status)//Server Success Response handler function
{
Console.log (data);
$ ("#img1"). attr ("src", data.imgpath1);
if (typeof (Data.error)! = ' undefined ') {
if (data.error! = ") {
alert (data.error);
} else {
alert (data.msg);
}
}
},
Error:function (data, status, E)//server response failure handler function
{
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.error) {
S.error.call (S.context | | s, XHR, status, E);
}

Fire the global callback
if (S.global) {
(S.context jQuery (s.context): jquery.event). Trigger ("Ajaxerror", [XHR, S, E]);
}
}

Ajax uploading files and frequently asked questions 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.