ajaxfileupload Syntax Error

     ajaxfileupload 采用的的jquery1.4之前的版本,所以用新版本的jquery会有一些兼容。

     主要问题有2点:

           1. handleError: 这个函数是1.4之前版本的函数。

           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] );
            }

           将该函数做为 fileupload给jquery扩展的函数的即可

           2. 对json 的处理, 见 uploadHttpData函数,

               data = (type == "xml" || data) ? r.responseXML : r.reponseText;

               这个只区分了 xml 和html 文本,根本没有json什么事。

               reponseText 默认会给 返回的文本信息添加一个 <pre>标签(操蛋的东西,不知道加这有什么用)

               所以问题来了,底下对 json 的处理是 eval("data =" +  data)(这个更操蛋,什么用没有, 就是 data = data),

               翻了网上找的好几篇文章处理方式都是  eval("data = \" " + data + " \" "), 这个相当于  data = ' " ' + data + ' " '; 毛用都没有,只是多了个

               双引号。

              好了问题找到了。那么解决就简单多了。

              首先去掉responseText 给数据多加的<pre> 标签: data = (type == "xml" || data) ? r.responseXML : $(r.reponseText).html();

              然后,当类型为json时: data = $.parseJSON(data);   为script是 将<pre>加上去。$(data).wrap('<pre></pre>');  搞定收工。

原文地址:https://www.cnblogs.com/jesseZh/p/3125755.html