简体   繁体   English

TypeError:无法读取未定义的属性“open”(Phonegap和Ionic)

[英]TypeError: Cannot read property 'open' of undefined (Phonegap and Ionic)

I'm building a mobile app using Phonegap Build and Ionic. 我正在使用Phonegap Build和Ionic构建移动应用程序。 I am trying to make an XMLHttpRequest to a web service to get some XML data. 我正在尝试为Web服务创建XMLHttpRequest以获取一些XML数据。 The web service requires 3 parameters. Web服务需要3个参数。 I keep getting the following error: 我一直收到以下错误:

ionic.bundle.js:26794 TypeError: Cannot read property 'open' of undefined. ionic.bundle.js:26794 TypeError:无法读取undefined属性'open'。

Any ideas as to what I might be doing wrong? 关于我可能做错什么的任何想法?

I have attached the entire method below. 我已经附上了下面的整个方法。

$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; 
  }   
};   
})

The problem is the httpObj object which is undefined and you try to access a method on undefined . 问题是httpObj对象未定义,您尝试访问undefined的方法。 The reason why you don't show the error message (when httpObj is undefined ) you have defined in the alert is that you condition is not correct. 您没有在警报中定义错误消息(当httpObj undefined )的原因是您的条件不正确。 This 这个

if(httpObj = undefined){

should had been like below: 应该像下面这样:

if(httpObj === undefined){

or equivalently like: 或者等同于:

if(httObj){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ionic:TypeError:无法读取未定义的属性“ ready” - Ionic: TypeError: Cannot read property 'ready' of undefined Angularjs / Ionic TypeError:无法读取未定义的属性'then' - Angularjs/Ionic TypeError: Cannot read property 'then' of undefined Ionic-2:无法读取未定义的属性“ open” - Ionic-2: Cannot read the property 'open' of undefined TypeError:无法读取未定义模态的属性“open” - TypeError: Cannot read property 'open' of undefined modal 错误TypeError:无法读取未定义的属性“打开” - ERROR TypeError: Cannot read property 'open' of undefined 未捕获的TypeError:无法读取未定义的属性“ open” - Uncaught TypeError: Cannot read property 'open' of undefined Phonegap构建-未捕获的TypeError:无法读取未定义的属性'getPicture' - Phonegap build - Uncaught TypeError: Cannot read property 'getPicture' of undefined 未捕获(承诺):类型错误:无法读取 ionic 2 应用程序中未定义的属性“应用” - Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined in ionic 2 app Ionic Framework中的RaphaelJS:TypeError:无法读取未定义的属性“路径” - RaphaelJS in Ionic Framework: TypeError: Cannot read property 'path' of undefined 使用 AngularJS 和 Ionic 出现错误“TypeError:无法读取未定义的属性‘email’” - Error "TypeError: Cannot read property 'email' of undefined" using AngularJS and Ionic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM