[英]IE8 Javascript null != undefined
我已经确定了问题,但不确定是什么真正导致了问题。 我的生产环境正在处理undefined和null相等( undefined == null
),这是所需的行为。 对于我的开发环境,该问题发生在IE8中,该开发环境对待null和undefined的区别对待( undefined != null
)。
我在下面提供了一段代码,这两种环境都相同。 调用render函数时,两种环境都不会传递任何参数。 我添加了控制台语句,以显示每种环境如何处理传递给render函数的args
。
var PortalView = (function() {
return new function() {
$.extend(true, this, SystemController);
var self = this;
//Render: 'args' is not defined in this case causing the issue
self.render = function(args){
if (args == null){ console.dir('null!!');}
if (args == undefined){ console.dir('undefined!!');}
if (args != undefined && args != null){console.dir('NEITHER');}
if (args == null && args == undefined){console.dir('BOTH!!');}
console.dir('args:'+args);
var args = (args != undefined) ? args : {};
args.el = (args.el != undefined) ? args.el : '#content'; //ERROR OCCURS HERE (line 21)
args.template = "PortalTemplate"; //HTML template
self.renderTemplate(args); //inherited from 'SystemController'
};
}
})();
这是控制台结果:
Production Environment (desired results):
LOG: "null!!"
LOG: "undefined!!"
LOG: "BOTH!!"
LOG: "args:undefined"
Development Environment (undesired results)
LOG: "null!!"
LOG: "args:undefined"
SCRIPT5007: Unable to get value of the property 'el': object is null or undefined
vwaPortalView.js, line 21 character 4
我正在寻找可能导致这种错误发生的方案。 任何提示将非常感谢。
编辑我已经确定了问题的真正根源。 这是由对跨站点(提供身份验证服务的内部Intranet站点)的JQUERY Ajax请求引起的。 jsonpCallback
参数破坏了一切。 如果有人知道什么可以拯救我的麻烦……太好了,否则我认为我应该能够从现在开始处理它! 我提供了ajax调用作为问题来源的参考(在IE8中)
$.ajax({
url: 'http://xyz.aspx', //changed for obvious reasons
dataType: 'jsonp',
jsonp: 'callback',
error: function (request, status, error) {console.dir(error);}, //Parse error
jsonpCallback: function(data, status){
console.dir(data);
console.dir(status);
}
});
使用typeof
var args = (typeof args === "undefined") ? {} : args;
所有浏览器均支持typeof
,并将返回元素的文本类型或“未定义”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.