---
title: " 用 ajaxFileUpload 出现的问题：has no method 'handleError'、返回json数据提示下载 、一直返回error "
author: "jackjobs"
date: "2014-07-09T10:04:17Z"
tags: []
categories: ["编程语言"]
slug: "ajaxfileupload-has-no-method-handleerror-json-error"
draft: false
lastmod: "2014-07-09T10:04:57Z"
id: 2089811
url: "https://phantomes.iteye.com/blog/2089811"
---

1\. 提示错误：Uncaught TypeError: Object function (a,b){return new d.fn.init(a,b,g)} has no method 'handleError'

目前找到两种情况会出现这个错误：

（1）、url地址没访问到

（2）、$.ajaxFileUpload中的dataType的值为小写，只需要把只该成大写就ok了。比如dataType : 'JSON'

 

```
jQuery.handleError is not a function 原因是handlerError只在jquery-1.4.2之前的版本中存在，jquery-1.6 和1.7中都没有这个函数了，因此在1.4.2中将这个函数复制到了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 ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
		}
	},
```

 

2.返回json数据在ie下提示下载 

解决方法：

设置content-type为text/html或plain/text

 

```
3.一直得到error ，无法执行指定的success方法。通过追踪ajaxFileUpload的执行过程发现，在调用它自身的uploadHttpData函数时，当执行if（type=="json")    eval("data = "+data);
会抛出异常，导致在处理异常的时候将status = "error" 因此一直执行error方法。
上网查询，得知eval函数是用来执行一段js代码，而并不是如我所想的反解json串
eval("data = "+data);的意思是 将data 赋值给 data参数 ，但是当我返回给页面的是一个简单的字符串，比如"OK" ，时，这样写就抛出异常。最后改为 eval("data = \" "+data+" \" ");即将返回的数据用双引号引起来当作字符串，然后赋给 data 。终于成功了。。。
```