Solution for js ajaxfileupload. js upload error: ajaxfileupload upload

Source: Internet
Author: User

Solution for js ajaxfileupload. js upload error: ajaxfileupload upload

I believe that file upload operations are often used in my work. Because I am engaged in front-end operations, I will mainly introduce ajax operations on the front-end. I have omitted a lot of code, and I directly use

$. AjaxFileUpload ({url: 'www. coding/mobi/file/uploadSingleFile.html ', // process the image script secureuri: false, fileElementId: 'image2', // file Control id. 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, there is no problem with uploading like this, but it always reports an error. I am sorry for the error. I remember to make up this article after a long time, but to modify its source code, the error can be solved.

The last part of its source code is like 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" )   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 in the <pre> label, the following code is added, // update by hzy var reg =/<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 ;}

In this way, you can use it normally.

Another situation:AjaxFileUpload reports this error jQuery. handleError is not a function

The handlerError method is available in versions earlier than 1.4.2. In this example, Jquery is 1.2,Solution:

To continue using ajaxfileupload to upload our attachments, we had to copy the following code to the ajaxfileupload. js file in our project.

handleError: function( s, xhr, status, e )   {     // If a local callback was 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] );         }   } 

The above is the solution to the errors reported by ajaxupload. js uploads. We hope to help you solve the problems and continue to pay attention to more highlights of the help house.

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.