如何让ajaxfileupload.js支持ie9,ie10,并可以传递多个参数

JavaScript011

如何让ajaxfileupload.js支持ie9,ie10,并可以传递多个参数,第1张

、如何让ajaxfileupload.js支持IE9、IE10?

打开ajaxfileupload 文件,找到下面的代码。

[javascript] view plaincopy

if(window.ActiveXObject) {

var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />')

if(typeof uri== 'boolean'){

io.src = 'javascript:false'

}

else if(typeof uri== 'string'){

io.src = uri

}

}

修改成如下:

[javascript] view plaincopy

if(window.ActiveXObject) {

if(jQuery.browser.version=="9.0" || jQuery.browser.version=="10.0"){

var io = document.createElement('iframe')

io.id = frameId

io.name = frameId

}else if(jQuery.browser.version=="6.0" || jQuery.browser.version=="7.0" || jQuery.browser.version=="8.0"){

var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />')

if(typeof uri== 'boolean'){

io.src = 'javascript:false'

}

else if(typeof uri== 'string'){

io.src = uri

}

}

}

2、如何让ajaxfileupload.js可以在文件上传的同时传递多个台数。

找到以下代码:

[javascript] view plaincopy

ajaxFileUpload: function(s) {

// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout

s = jQuery.extend({}, jQuery.ajaxSettings, s)

var id = new Date().getTime()

var form = jQuery.createUploadForm(id, s.fileElementId)

增加自己要传递的参数:

[javascript] view plaincopy

ajaxFileUpload: function(s) {

// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout

s = jQuery.extend({}, jQuery.ajaxSettings, s)

var id = new Date().getTime()

var form = jQuery.createUploadForm(id, s.fileElementId, s.tag_name, s.tag_link, s.tag_sort, s.tag_status, s.tag_id)

这里我们增加了五个传递参数。 s.tag_name, s.tag_link, s.tag_sort, s.tag_status, s.tag_id

在做ajaxFileUpload时,我也遇到这个问题,同时还有其它的问题,用了一下午的时间解决了:

问题1:如楼主所说,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:一直得到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 。终于成功了。。。

贴出来,希望可以帮助到其他同样遇到这个问题的人。

ajaxFileUpload自定义参数,后台获取的时候为null

解决办法:修改ajaxFileUpload.js文件中createUploadForm()函数,新增传入参数data,并创建hidden控件,存储自定义参数

createUploadForm: function (id, fileElementId, data) {

....

if (data) {

}

找到ajaxFileUpload.js文件中调用createUploadForm()函数的地方,传入产生即可

ajaxFileUpload: function (s) {

...

var form = jQuery.createUploadForm(id, s.fileElementId,s.data)

...

}