码迷,mamicode.com
首页 > Web开发 > 详细

ajaxupload.js上传报错

时间:2015-12-02 10:31:33      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

相信大家在工作中经常用到文件上传的操作,因为我是搞前端的,所以这里主要是介绍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);
                        }
                   })

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

 

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

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

 将这一段改为这样子

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" ){
            //  因为json数据会被<pre>标签包着,所以有问题,现在添加以下代码,
            //  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;
    }

  这样就可以正常使用了

 

ajaxupload.js上传报错

标签:

原文地址:http://www.cnblogs.com/xianyulaodi/p/5012151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!