ajaxfileupload 半成品遇到的问题,不走success 走error的问题


大部分都是datatype 为 json的时候遇到的

1.遇到json被加pre标签  去掉

2.遇到json被加audio 标签 去掉

3.遇到json转换错误,换方式转


改后的代码如下  , 有注释

  1. uploadHttpData: function( r, type ) {
  2. var data = !type;
  3. data = type == "xml" || data ? r.responseXML : r.responseText;
  4. // If the type is "script", eval it in global context
  5. if ( type == "script" )
  6. jQuery.globalEval( data );
  7. // Get the JavaScript object, if JSON is used.
  8. if ( type == "json" ){
  9. //处理会加pre标签
  10. if(data.indexOf('<pre>') != -1) {
  11. data = data.substring(5, data.length-6);
  12. }
  13. //处理会加audio标签
  14. if(data.indexOf('<audio') != -1) {
  15. data = data.substring(0, data.indexOf('<audio'));
  16. }
  17. //改变原来的转换json逻辑
  18. data = jQuery.parseJSON(data);
  19. }
  20. // evaluate scripts within html
  21. if ( type == "html" )
  22. jQuery("<div>").html(data).evalScripts();
  23. //alert($('param', data).each(function(){alert($(this).attr('value'));}));
  24. return data;
  25. }


原文地址:https://www.cnblogs.com/signheart/p/865d32d96c20834020773595cd7d291c.html