exception : SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5) 思路分析: 第一步:兼容IE9,firefox,Opera,Safari等浏览器; var iframe = document.createElement("iframe"); iframe.setAttribute("id","yui-history-iframe"); iframe.setAttribute("src","../../images/defaults/transparent-pixel.gif"); iframe.setAttribute("style","position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;") 第二步:兼容IE6-8:由于ie6-8 不能修改iframe的name属性 var oFrame = isIE ? document.createElement("<iframe name=/"" + this._FrameName + "/">") : document.createElement("iframe"); oFrame.name = "iframName";
1、如何让ajaxfileupload.js支持IE9、IE10? 打开ajaxfileupload 文件,找到下面的代码。
[javascript]
view plain
copy
- if(window.ActiveXObject){
- vario=document.createElement('<iframeid="'+frameId+'"name="'+frameId+'"/>');
- if(typeofuri=='boolean'){
- io.src='javascript:false';
- }
- elseif(typeofuri=='string'){
- io.src=uri;
- }
- }
修改成如下:
[javascript]
view plain
copy
- if(window.ActiveXObject){
- if(jQuery.browser.version=="9.0"||jQuery.browser.version=="10.0"){
- vario=document.createElement('iframe');
- io.id=frameId;
- io.name=frameId;
- }elseif(jQuery.browser.version=="6.0"||jQuery.browser.version=="7.0"||jQuery.browser.version=="8.0"){
- vario=document.createElement('<iframeid="'+frameId+'"name="'+frameId+'"/>');
- if(typeofuri=='boolean'){
- io.src='javascript:false';
- }
- elseif(typeofuri=='string'){
- io.src=uri;
- }
- }
- }
2、如何让ajaxfileupload.js可以在文件上传的同时传递多个台数。 找到以下代码:
[javascript]
view plain
copy
- ajaxFileUpload:function(s){
- //TODOintroduceglobalsettings,allowingtheclienttomodifythemforallrequests,notonlytimeout
- s=jQuery.extend({},jQuery.ajaxSettings,s);
- varid=newDate().getTime()
- varform=jQuery.createUploadForm(id,s.fileElementId);
增加自己要传递的参数:
[javascript]
view plain
copy
- ajaxFileUpload:function(s){
- //TODOintroduceglobalsettings,s.fileElementId,s.tag_name,s.tag_link,s.tag_sort,s.tag_status,s.tag_id);
这里我们增加了五个传递参数。s.tag_name,s.tag_id 接着找到:
[javascript]
view plain
copy
- createUploadForm:function(id,fileElementId,tag_name,tag_link,tag_sort,tag_status,tag_id)//增加tag_name,tag_id
- {
- //createform
- varformId='jUploadForm'+id;
- varfileId='jUploadFile'+id;
- //--增加以下内容
- vartagNameId='tag_name'+id;
- vartagLinkId='tag_link'+id;
- vartagSortId='tag_sort'+id;
- vartagStatusId='tag_status'+id;
- vartagIdId='tag_id'+id;
- //--end
- varform=$('<formaction=""method="POST"name="'+formId+'"id="'+formId+'"enctype="multipart/form-data"></form>');
- varoldElement=$('#'+fileElementId);
- varnewElement=$(oldElement).clone();
- //--增加以下内容
- vartagNameElement='<inputtype="text"name="tag_name"value="'+tag_name+'">';
- vartagLinkElement='<inputtype="text"name="tag_link"value="'+tag_link+'">';
- vartagSortElement='<inputtype="text"name="tag_sort"value="'+tag_sort+'">';
- vartagStatusElement='<inputtype="text"name="tag_status"value="'+tag_status+'">';
- vartagIdElement='<inputtype="text"name="tag_id"value="'+tag_id+'">';
- //--end
- $(oldElement).attr('id',fileId);
- $(oldElement).before(newElement);
- $(oldElement).appendTo(form);
- //--增加以下的内容
- $(tagNameElement).appendTo(form);
- $(tagLinkElement).appendTo(form);
- $(tagSortElement).appendTo(form);
- $(tagStatusElement).appendTo(form);
- $(tagIdElement).appendTo(form);
- //--end
- //setattributes
- $(form).css('position','absolute');
- $(form).css('top','-1200px');
- $(form).css('left','-1200px');
- $(form).appendTo('body');
- returnform;
- },
注意注释中的内容为增加了内容。 修改完后,如何使用?
[javascript]
view plain
copy
- $.ajaxFileUpload({
- url:web_url,
- secureuri:false,
- //以下为增加的传递参数
- tag_name:tag_name,
- tag_link:tag_link,
- tag_sort:tag_sort,
- tag_status:tag_status,
- tag_id:tag_id,
- //--end
- fileElementId:result[0],
- dataType:'json',
- success:function(data,status){}
- //以下省略
OK,done. 附ajaxfileupload完整版:
[javascript]
view plain
copy
- jQuery.extend({
-
-
- createUploadIframe:function(id,uri)
- {
- //createframe
- varframeId='jUploadFrame'+id;
-
- if(window.ActiveXObject){
- //vario=document.createElement('<iframeid="'+frameId+'"name="'+frameId+'"/>');
- //if(typeofuri=='boolean'){
- //io.src='javascript:false';
- //}
- //elseif(typeofuri=='string'){
- //io.src=uri;
- //}
-
- //fixie9andie10-------------
- if(jQuery.browser.version=="9.0"||jQuery.browser.version=="10.0"){
- vario=document.createElement('iframe');
- io.id=frameId;
- io.name=frameId;
- }elseif(jQuery.browser.version=="6.0"||jQuery.browser.version=="7.0"||jQuery.browser.version=="8.0"){
- vario=document.createElement('<iframeid="'+frameId+'"name="'+frameId+'"/>');
- if(typeofuri=='boolean'){
- io.src='javascript:false';
- }
- elseif(typeofuri=='string'){
- io.src=uri;
- }
- }
- }
- else{
- vario=document.createElement('iframe');
- io.id=frameId;
- io.name=frameId;
- }
- io.style.position='absolute';
- io.style.top='-1000px';
- io.style.left='-1000px';
-
- document.body.appendChild(io);
-
- returnio
- },
- createUploadForm:function(id,tag_id)
- {
- //createform
- varformId='jUploadForm'+id;
- varfileId='jUploadFile'+id;
- //--
- vartagNameId='tag_name'+id;
- vartagLinkId='tag_link'+id;
- vartagSortId='tag_sort'+id;
- vartagStatusId='tag_status'+id;
- vartagIdId='tag_id'+id;
- //--end
- varform=$('<formaction=""method="POST"name="'+formId+'"id="'+formId+'"enctype="multipart/form-data"></form>');
- varoldElement=$('#'+fileElementId);
- varnewElement=$(oldElement).clone();
- //--
- vartagNameElement='<inputtype="text"name="tag_name"value="'+tag_name+'">';
- vartagLinkElement='<inputtype="text"name="tag_link"value="'+tag_link+'">';
- vartagSortElement='<inputtype="text"name="tag_sort"value="'+tag_sort+'">';
- vartagStatusElement='<inputtype="text"name="tag_status"value="'+tag_status+'">';
- vartagIdElement='<inputtype="text"name="tag_id"value="'+tag_id+'">';
- //--end
- $(oldElement).attr('id',fileId);
- $(oldElement).before(newElement);
- $(oldElement).appendTo(form);
- //--
- $(tagNameElement).appendTo(form);
- $(tagLinkElement).appendTo(form);
- $(tagSortElement).appendTo(form);
- $(tagStatusElement).appendTo(form);
- $(tagIdElement).appendTo(form);
- //--end
- //setattributes
- $(form).css('position',
-
- ajaxFileUpload:function(s){
- //TODOintroduceglobalsettings,s.tag_id);
- vario=jQuery.createUploadIframe(id,s.secureuri);
- varframeId='jUploadFrame'+id;
- varformId='jUploadForm'+id;
- //Watchforanewsetofrequests
- if(s.global&&!jQuery.active++)
- {
- jQuery.event.trigger("ajaxStart");
- }
- varrequestDone=false;
- //Createtherequestobject
- varxml={}
- if(s.global)
- jQuery.event.trigger("ajaxSend",[xml,s]);
- //Waitforaresponsetocomeback
- varuploadCallback=function(isTimeout)
- {
- vario=document.getElementById(frameId);
- try
- {
- if(io.contentWindow)
- {
- xml.responseText=io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
- xml.responseXML=io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
-
- }elseif(io.contentDocument)
- {
- xml.responseText=io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
- xml.responseXML=io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
- }
- }catch(e)
- {
- jQuery.handleError(s,xml,null,e);
- }
- if(xml||isTimeout=="timeout")
- {
- requestDone=true;
- varstatus;
- try{
- status=isTimeout!="timeout"?"success":"error";
- //Makesurethattherequestwassuccessfulornotmodified
- if(status!="error")
- {
- //processthedata(runsthexmlthroughhttpDataregardlessofcallback)
- vardata=jQuery.uploadHttpData(xml,s.dataType);
- //Ifalocalcallbackwasspecified,fireitandpassitthedata
- if(s.success)
- s.success(data,status);
-
- //Firetheglobalcallback
- if(s.global)
- jQuery.event.trigger("ajaxSuccess",s]);
- }else
- jQuery.handleError(s,status);
- }catch(e)
- {
- status="error";
- jQuery.handleError(s,status,e);
- }
-
- //Therequestwascompleted
- if(s.global)
- jQuery.event.trigger("ajaxComplete",s]);
-
- //HandletheglobalAJAXcounter
- if(s.global&&!--jQuery.active)
- jQuery.event.trigger("ajaxStop");
-
- //Processresult
- if(s.complete)
- s.complete(xml,status);
-
- jQuery(io).unbind()
-
- setTimeout(function()
- {try
- {
- $(io).remove();
- $(form).remove();
-
- }catch(e)
- {
- jQuery.handleError(s,e);
- }
-
- },100)
-
- xml=null
-
- }
- }
- //Timeoutchecker
- if(s.timeout>0)
- {
- setTimeout(function(){
- //Checktoseeiftherequestisstillhappening
- if(!requestDone)uploadCallback("timeout");
- },s.timeout);
- }
- try
- {
- //vario=$('#'+frameId);
- varform=$('#'+formId);
- $(form).attr('action',s.url);
- $(form).attr('method','POST');
- $(form).attr('target',frameId);
- if(form.encoding)
- {
- form.encoding='multipart/form-data';
- }
- else
- {
- form.enctype='multipart/form-data';
- }
- $(form).submit();
-
- }catch(e)
- {
- jQuery.handleError(s,e);
- }
- if(window.attachEvent){
- document.getElementById(frameId).attachEvent('onload',uploadCallback);
- }
- else{
- document.getElementById(frameId).addEventListener('load',uploadCallback,false);
- }
- return{abort:function(){}};
-
- },
-
- uploadHttpData:function(r,type){
- vardata=!type;
- data=type=="xml"||data?r.responseXML:r.responseText;
- //Ifthetypeis"script",evalitinglobalcontext
- if(type=="script")
- jQuery.globalEval(data);
- //GettheJavaScriptobject,ifJSONisused.
- if(type=="json")
- eval("data="+data);
- //evaluatescriptswithinhtml
- if(type=="html")
- jQuery("<div>").html(data).evalScripts();
- //alert($('param',data).each(function(){alert($(this).attr('value'));}));
- returndata;
- }
- })
-
转载:http://www.52php.cn/article/p-xjquddto-gy.html
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|