Home Web Front-end JS Tutorial js ajaxfileupload.js upload error solution_javascript skills

js ajaxfileupload.js upload error solution_javascript skills

May 16, 2016 pm 03:02 PM
js upload Report an error

相信大家在工作中经常用到文件上传的操作,因为我是搞前端的,所以这里主要是介绍ajax在前端中的操作。代码我省略的比较多,直接拿js那里的

$.ajaxFileUpload({
      url:'www.coding/mobi/file/uploadSingleFile.html',//处理图片脚本
      secureuri :false,
      fileElementId :'image2',//file控件id。就是input type="file" id="image2"
      dataType : 'json',
      success : function (data, status){
       console.log(data);
      },
      error: function(data, status, e){
       alert(e);
      }
     })
Copy after login

按照教程,这样子上传的话是没有问题的,可是它一直有一个报错。报的是什么错有点忘了,不好意思 ,因为用完很久才记得补回这篇文章,但是要修改它的源码,那个错误就可以解决了

它源码的最后一段是这样子的

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;
 }
Copy after login

将这一段改为这样子

uploadHttpData: function( r, type ) {
  var data = !type;
  data = type == "xml" || data &#63; 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" ){
   // 因为json数据会被<pre class="brush:php;toolbar:false">标签包着,所以有问题,现在添加以下代码,
   // update by hzy
   var reg = /<pre.+&#63;>(.+)<\/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;
 }
Copy after login

这样就可以正常使用了。

另一种情况:ajaxFileUpload 报这错jQuery.handleError is not a function

版本1.4.2之前的版本才有handlerError方法,例子里使用的Jquery是1.2的,解决方法:

为了能够继续使用ajaxfileupload上传我们的附件,只好将下面代码拷进我们的项目中的ajaxfileupload.js文件中

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 &#63; jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] ); 
        } 
  } 
Copy after login

以上就是面对ajaxupload.js上传报错问题的解决方法,希望能帮助大家解决困难,也希望大家继续关注脚本之家更多精彩内容。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Cause analysis: HTTP request error 504 gateway timeout Cause analysis: HTTP request error 504 gateway timeout Feb 19, 2024 pm 05:12 PM

Brief introduction to the reason for the http request error: 504GatewayTimeout: During network communication, the client interacts with the server by sending HTTP requests. However, sometimes we may encounter some error messages during the process of sending the request. One of them is the 504GatewayTimeout error. This article will explore the causes and solutions to this error. What is the 504GatewayTimeout error? GatewayTimeo

Solution: Socket Error when handling HTTP requests Solution: Socket Error when handling HTTP requests Feb 25, 2024 pm 09:24 PM

http request error: Solution to SocketError When making network requests, we often encounter various errors. One of the common problems is SocketError. This error is thrown when our application cannot establish a connection with the server. In this article, we will discuss some common causes and solutions of SocketError. First, we need to understand what Socket is. Socket is a communication protocol that allows applications to

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Simple steps to upload your own music on Kugou Simple steps to upload your own music on Kugou Mar 25, 2024 pm 10:56 PM

1. Open Kugou Music and click on your profile picture. 2. Click the settings icon in the upper right corner. 3. Click [Upload Music Works]. 4. Click [Upload Works]. 5. Select the song and click [Next]. 6. Finally, click [Upload].

How to upload lyrics to QQ Music How to upload lyrics to QQ Music Feb 23, 2024 pm 11:45 PM

With the advent of the digital age, music platforms have become one of the main ways for people to obtain music. However, sometimes when we listen to songs, we find that there are no lyrics, which is very disturbing. Many people hope that lyrics can be displayed when listening to songs to better understand the content and emotions of the songs. QQ Music, as one of the largest music platforms in China, also provides users with the function of uploading lyrics, so that users can better enjoy music and feel the connotation of the songs. The following will introduce how to upload lyrics on QQ Music. first

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

How to improve computer upload speed How to improve computer upload speed Jan 15, 2024 pm 06:51 PM

Upload speed becomes very slow? I believe this is a problem that many friends will encounter when uploading things on their computers. If the network is unstable when using a computer to transfer files, the upload speed will be very slow. So how can I increase the network upload speed? Below, the editor will tell you how to solve the problem of slow computer upload speed. When it comes to network speed, we all know that the speed of opening web pages, download speed, and upload speed are also very critical. Especially some users often need to upload files to the network disk, so a fast upload speed will undoubtedly save you a lot of money. Less time, what should I do if the upload speed is slow? Below, the editor brings you pictures and texts on how to deal with slow computer upload speeds. How to solve the problem of slow computer upload speed? Click "Start--Run" or "Window key"

See all articles