Cannot read property 'defaultView' of undefined 报错解决

  当我们在一个事件方法中去使用$.ajax进行数据交互时

	$(‘.btn_box‘).click(function() {
		$.ajax({
			type: ‘post‘,
			url: ‘‘,
			dataType: ‘json‘,
			contentType: ‘application/json; charset=utf-8‘,
			async: false,
			success: function(res) {
				console.log($(this))

			}
		})
	})

  

  此时在console 会报如标题一样的错误,

    1.因为 $ .ajax()中的$ (this)已经不是我之前所处理的了,在$ .ajax()中它指的是 ajax jQuery对象本身;

  解决办法:  

	$(‘.btn_box‘).click(function() {
		$.ajax({
                        context: this,
			type: ‘post‘,
			url: ‘‘,
			dataType: ‘json‘,
			contentType: ‘application/json; charset=utf-8‘,
			async: false,
			success: function(res) {
				console.log($(this))

			}
		})
	})

  只需要在ajax中加一个 context:this  锁定当前元素即可  问题解决!!!

    

Cannot read property 'defaultView' of undefined 报错解决

原文地址:https://www.cnblogs.com/luke-fan/p/12003864.html

时间: 2024-08-01 09:25:43

Cannot read property 'defaultView' of undefined 报错解决的相关文章

vue 报错解决:TypeError: Cannot read property '_t' of undefined"

前端报错如下: [Vue warn]: Error in render: "TypeError: Cannot read property '_t' of undefined" 是在项目中用了多语言配置,vue 跟 i18n之间的兼容问题.解决方法如下: Vue.use(iView) 替换成 Vue.use(iView, { i18n: function(path, options) { let value = i18n.t(path, options) if (value !== n

Cannot read property 'defaultView' of undefined js操作异常

在function(obj){}函数中操作对象时,突然遇到"Cannot read property 'defaultView' of undefined"js报错! 打印出obj即可发现问题,在js函数传参时$(this)传递的是父类的jquary对象,this传递的是父类HTML对象.当this包含在B函数对象中调用时,需要在调用B之前把this复制一份var thisObj=this. Cannot read property 'defaultView' of undefined

quick3.3final版创建项目报错解决

quick3.3final版创建项目报错解决 今天新下载了quick3.3final版,于是安装,创建项目,打开player新建项目如下图 然后点击创建,就发生了如下错误,相信应该有不少朋友会碰到的 首先,这里有两个错误 1.PHP Notice:  Undefined index: extracmd in /Users/wangmeng/Documents/quick-3.3/quick/bin/lib/quick/ProjectCreator.php on line 117 这是117行有未

Centos6.3 PHP编译安装JSON模块报错解决

我在搭建监控系统时候出现JSON模块安装失败,PHP5.3  系统Centos6.3,安装json报错 ZVAL_DELREF 符号未知错误... # Warning: PHP Startup: Unable to load dynamic library '/home/json/json-1.2.1/modules/json.so' - /home/json/json-1.2.1/modules/json.so: undefined symbol: ZVAL_DELREF in Unknown

jquery IE6 select.val() bug报错解决办法

原文地址:http://hi.baidu.com/kinghmx/item/395dbac3261292dcef183b52 最近在写一个页面,在出了ie6外的所有浏览器中都正常(ie7,8,9,  firefox, chrome), IE6下提示 “无法设置selected属性.未指明的错误”. 后来发现是jquery 在 ie6 下操作 select控件有BUG. 我程序中是这样使用的: $("#genre").val(0); 改成: setTimeout(function(){ 

Spring集成JPA配置懒加载两个报错解决办法

一:报错no session 因为entitymanager对象在事物提交后就关闭了 报错的 no session相当于sql的session 解决办法:解决办法 在web.xmL配置一个过滤器 使其在这个session中的manager在结束后再关闭open <!--配置openmanager--> <filter> <filter-name>openEntity</filter-name> <filter-class>org.springfr

Qt类声明中Q_OBJECT的作用与报错解决

2017-06-22 周四 大雨 北京 院里 新建作图类,继承自QCUstomPlot类 因为需要同时作8张图,都要单坐标缩放的功能,因此想干脆新建一个类,继承自QCUstomPlot,把需要的功能都加上.类名取为QCUstomPlotPlus,最终成功版类代码如下: //声明.explicit是为了禁止隐式转换. class QCustomPlotPlus : public QCustomPlot { Q_OBJECT //重要! public: explicit QCustomPlotPlu

Oracle11g 启动报错ORA-00845: MEMORY_TARGET not supported on this system报错解决

ORA-00845: MEMORY_TARGET not supported on this system报错解决 Oracle启动报错 ORA-00845: MEMORY_TARGET not supported on this system报错解决 SQL> startup ORA-00845: MEMORY_TARGET not supported on this system 查看原本大小 [[email protected] oracle]# df -h|grep shm tmpfs

【Unity3D】生成工程报错解决—UnityEditor.HostView:OnGUI() Error building Player: Couldn&#39;t build player because of unsupported data on target platform.

错误 错误1:An asset is marked as dont save, but is included in the build: unityEditor.HostView:OnGUI() 错误2:Building - Failed to write file: sharedassets0.assetsUnityEditor.HostView:OnGUI() 错误3:Error building Player: Couldn't build player because of unsup