TypeError: Cannot read property '未定义(Phonegap和Ionic)
TypeError: Cannot read property 'open' of undefined (Phonegap and Ionic)
我正在使用Phonegap Build和Ionic构建一个移动应用程序。我正试图使XMLHttpRequest到web服务以获得一些XML数据。web服务需要3个参数。我一直得到以下错误:
ionic.bundle.js:26794 TypeError:无法读取属性'open'定义。
你知道我可能做错了什么吗?
我在下面附上了整个方法。
$scope.result = function callService(requestAction, requestXML){
var httpObj = undefined;
if(window.XMLHttpRequest){
httpObj = new XMLHttpRequest();
}
else if (window.ActiveXObject){
httpObj = new ActiveXObject("Microsoft.XMLHTTP");
}
if(httpObj = undefined){
alert("Failed creating Http Object");
return "";
}
if(requestAction == undefined || requestAction == null){
requestAction = "";
}
var async = false;
var url = "theurl";
var systemID = "thesystemid";
var requestAction = "GetEnquiry";
var requestXML = "therequestxml";
var params = "SystemID=" + systemID + "&RequestAction=" + requestAction + "&RequestXML=" + requestXML + "&OutputFormat=JSON";
var headers = "Content-type , application/x-www-form-urlencoded; charset=UTF-8";
httpObj.open("POST", url, async);
httpObj.send(params);
if(httpObj.readyState == 4 && httpObj.status == 200){
var result = httpObj.responseText;
console.log("This is the result: " + result);
return result;
}
else {
var result = httpObj.responseText;
return result;
}
};
})
问题是未定义的httpObj
对象,您尝试访问undefined
上的方法。不显示在警报中定义的错误消息(当httpObj
为undefined
时)的原因是您的条件不正确。这个
if(httpObj = undefined){
应该像下面这样:
if(httpObj === undefined){
或类似的
if(httObj){
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 在Phonegap中重定向到新页面后,AdMob未定义
- PhoneGap无法调用未定义的方法loadurl
- Cordova:未捕获引用错误:chbrody没有使用SQLitePlugin.js定义PhoneGap
- Phonegap 和 window.device 在 onDeviceReady for iOS7 中未定义
- PhoneGap: 引用错误: 未定义连接
- Phonegap函数未在Phonegap构建应用程序中定义 - 推送通知也不起作用
- PhoneGap:admob 是未定义的
- 值未从输入错误插入数据库:phonegap中未定义
- Phonegap媒体:“;引用错误介质未定义”;
- Phonegap内部版本-未捕获类型错误:无法读取属性'getPicture'的未定义
- 套接字.在Phonegap移动应用程序中未定义的变量
- navigator.device在PHONEGAP - CORDOVA中未定义
- PhoneGap InAppBrowser的URL在loadstart中未定义
- TypeError: Cannot read property '未定义(Phonegap和Ionic)
- Phonegap 相机 API - 无法读取未定义的属性“DATA_URL”
- 未捕获类型错误:不能调用方法'方法名'未定义的phonegap android
- Phonegap jQuery:不能调用未定义的方法confirm
- Phonegap插件不工作-连接未定义