在本文中,我们将详细介绍UncaughtTypeError:(intermediatevalue)(...)isnotafunction的各个方面,同时,我们也将为您带来关于ajaxfileuploa
在本文中,我们将详细介绍Uncaught TypeError: (intermediate value)(...) is not a function的各个方面,同时,我们也将为您带来关于ajaxfileupload.js 报Uncaught TypeError: jQuery.handleError is not a function错误、angular-translate 报错 Uncaught TypeError: f.has is not a function、antd Upload上传报Uncaught TypeError: items.map is not a function错误、axios 源升级导致异常Uncaught TypeError: axios is not a function的有用知识。
本文目录一览:- Uncaught TypeError: (intermediate value)(...) is not a function
- ajaxfileupload.js 报Uncaught TypeError: jQuery.handleError is not a function错误
- angular-translate 报错 Uncaught TypeError: f.has is not a function
- antd Upload上传报Uncaught TypeError: items.map is not a function错误
- axios 源升级导致异常Uncaught TypeError: axios is not a function
Uncaught TypeError: (intermediate value)(...) is not a function
当我在闭包中将 js 逻辑编写为单个 js 文件时,一切正常,如下所示:
(function(win){
//main logic here
win.expose1 = ....
win.expose2 = ....
})(window)
但是当我尝试在同一个 js 文件中的闭包之前插入一个日志记录替代函数时,
window.Glog = function(msg){
console.log(msg)
}
// this was added before the main closure.
(function(win){
//the former closure that contains the main javascript logic;
})(window)
它抱怨有一个TypeError:
Uncaught TypeError: (intermediate value)(...) is not a function
我做错了什么?
ajaxfileupload.js 报Uncaught TypeError: jQuery.handleError is not a function错误
因为“handleError”函数是在低版本的jquery 中的函数,所以解决方案是从低版本中的jquery 中找到这个函数
handleError: function( s,xhr,status,e ) { // If a local callback was specified,fire it if ( s.error ) { s.error.call( s.context || s,e ); } // Fire the global callback if ( s.global ) { (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError",[xhr,s,e] ); } }
把这个函数加入ajaxfileupload.js中去,就不报错了。
jQuery.extend({ createUploadIframe: function(id,uri) { //create frame var frameId = 'jUploadFrame' + id; 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; } } else { var io = 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); return io },createUploadForm: function(id,fileElementId) { //create form var formId = 'jUploadForm' + id; var fileId = 'jUploadFile' + id; var form = $('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>'); var oldElement = $('#' + fileElementId); var newElement = $(oldElement).clone(); $(oldElement).attr('id',fileId); $(oldElement).before(newElement); $(oldElement).appendTo(form); //set attributes $(form).css('position','absolute'); $(form).css('top','-1200px'); $(form).css('left','-1200px'); $(form).appendTo('body'); return form; },//就是这个函数。 handleError: function( s,e] ); } },addOtherRequestsToForm: function(form,data) { // add extra parameter var originalElement = $('<input type="hidden" name="" value="">'); for (var key in data) { name = key; value = data[key]; var cloneElement = originalElement.clone(); cloneElement.attr({'name':name,'value':value}); $(cloneElement).appendTo(form); } return form; },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); if ( s.data ) form = jQuery.addOtherRequestsToForm(form,s.data); var io = jQuery.createUploadIframe(id,s.secureuri); var frameId = 'jUploadFrame' + id; var formId = 'jUploadForm' + id; // Watch for a new set of requests if ( s.global && ! jQuery.active++ ) { jQuery.event.trigger( "ajaxStart" ); } var requestDone = false; // Create the request object var xml = {} if ( s.global ) jQuery.event.trigger("ajaxSend",[xml,s]); // Wait for a response to come back var uploadCallback = function(isTimeout) { var io = 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; }else if(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; var status; try { status = isTimeout != "timeout" ? "success" : "error"; // Make sure that the request was successful or notmodified if ( status != "error" ) { // process the data (runs the xml through httpData regardless of callback) var data = jQuery.uploadHttpData( xml,s.dataType ); // If a local callback was specified,fire it and pass it the data if ( s.success ) s.success( data,status ); // Fire the global callback if( s.global ) jQuery.event.trigger( "ajaxSuccess",s] ); } else jQuery.handleError(s,status); } catch(e) { status = "error"; jQuery.handleError(s,e); } // The request was completed if( s.global ) jQuery.event.trigger( "ajaxComplete",s] ); // Handle the global AJAX counter if ( s.global && ! --jQuery.active ) jQuery.event.trigger( "ajaxStop" ); // Process result 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 } } // Timeout checker if ( s.timeout > 0 ) { setTimeout(function(){ // Check to see if the request is still happening if( !requestDone ) uploadCallback( "timeout" ); },s.timeout); } try { // var io = $('#' + frameId); var form = $('#' + 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 ) { 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" ) { // If you add mimetype in your response,// you have to delete the '<pre></pre>' tag. // The pre tag in Chrome has attribute,so have to use regex to remove var data = r.responseText; var rx = new RegExp("<pre.*?>(.*?)</pre>","i"); var am = rx.exec(data); //this is the desired data extracted var data = (am) ? am[1] : ""; //the only submatch or empty 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; } })
angular-translate 报错 Uncaught TypeError: f.has is not a function
Index{{hello | translate}}
antd Upload上传报Uncaught TypeError: items.map is not a function错误
使用antd里面的Upload来上传文件,写好之后运行报错。。。
代码是这样的:
const uploadProps = {
action: createTheURL(''software/stu/score'', ''upload''),
method: ''POST'',
headers: {
authorization: tokenHandler.getSessionByKey(''authorization'')
},
onRemove: this.handleRemove
}
<Form.Item
label=''附件''
>{getFieldDecorator(''appendix'', {
initialValue: JSON.parse(appendix) || [],
valuePropName: ''fileList'',
})(<Upload {...uploadProps} >
<a style={{ marginRight: 20 }}>
<Icon type="plus" />添加附件
</a>
<span>(最多上传10个文件,单个文件不能超过20M)</span>
</Upload>)}
</Form.Item>
造成这个问题的原因是,因为在上传了一个文件之后,会有产生一个新的fileList,但是这个新的fileList没有回传到Upload组件的fileList里面,所以只要我们把新的fileList给到Upload,那么这个问题就可以解决了。
最开始的做法是,将fileList存到state里面,然后每次上传文件就会触发Upload的onChange函数,在onChange函数里面使用setState将新的fileList包存到state里面,最后在将state里面的fileList放到Upload里面。
代码大概就是这个样子:
handleChange = info => {
const { fileList } = info;
this.setSate({
fileList
});
}
render(){
const { fileList } = this.state;
const uploadProps = {
action: createTheURL(''software/stu/score'', ''upload''),
method: ''POST'',
headers: {
authorization: tokenHandler.getSessionByKey(''authorization'')
},
fileList,
onRemove: this.handleRemove,
onChange: this.handleChange
};
return (
<Form.Item
label=''附件''
>
<Upload {...uploadProps} >
<a style={{ marginRight: 20 }}>
<Icon type="plus" />添加附件
</a>
<span>(最多上传10个文件,单个文件不能超过20M)</span>
</Upload>
</Form.Item>
)
}
但是这样写,在后面还是会有一些问题,这里只用来处理新增表单数据没问题;但是如果是要对上传之后的表单数据进行一个修改的话就会出现问题。
因为在修改的时候,需要先获取已经提交了的数据,对于已经上传了的文件需要先获取到文件名,生成fileList存到state里面,然后再放到Upload组件里面,如果这样写的话,最后就会发现整个流程就很混乱,而且也不一定完全没问题。
最终解决办法:
直接使用antd Form组件里面的getValueFromEvent方法,这个方法的作用就是把onChange的参数回传到Upload里面(这里的参数就是file和fileList)。
antd Form组件
我写的代码如下:
const uploadProps = {
action: createTheURL(''software/stu/score'', ''upload''),
method: ''POST'',
headers: {
authorization: tokenHandler.getSessionByKey(''authorization'')
},
onRemove: this.handleRemove
}
<Form.Item
label=''附件''
>{getFieldDecorator(''appendix'', {
initialValue: JSON.parse(appendix) || [],
valuePropName: ''fileList'',
getValueFromEvent: e => {
if (Array.isArray(e)) {
return e;
}
return e && e.fileList;
}
})(<Upload {...uploadProps} >
<a style={{ marginRight: 20 }}>
<Icon type="plus" />添加附件
</a>
<span>(最多上传10个文件,单个文件不能超过20M)</span>
</Upload>)}
</Form.Item>
axios 源升级导致异常Uncaught TypeError: axios is not a function
问题现象
已经稳定运行近一年的项目,2022年10月7日10点,客户反馈,用户请求无法触发,怎么点都不好使~
查看请求日志,发现2022年10月7日凌晨1点多axios请求日志没有了。
定位
https://unpkg.com/axios/dist/axios.min.js 访问302,重定向到https://unpkg.com/axios@1.1.0/dist/axios.min.js。
导致客户端代码报错:Uncaught TypeError: axios is not a function...
https://unpkg.com/axios/dist/axios.min.js 之前的源码对应的是0.*.*版本,是可以直接在代码中使用 axions()对应api方法的。升级后,导致axios找不到。
解决方案
替换引入为:<script src="https://unpkg.com/axios@0.18.1/dist/axios.min.js"></script>
后话
unpkg官方这操作也太草率了吧~
关于Uncaught TypeError: (intermediate value)(...) is not a function的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于ajaxfileupload.js 报Uncaught TypeError: jQuery.handleError is not a function错误、angular-translate 报错 Uncaught TypeError: f.has is not a function、antd Upload上传报Uncaught TypeError: items.map is not a function错误、axios 源升级导致异常Uncaught TypeError: axios is not a function的相关信息,请在本站寻找。
本文标签: