【问题标题】:Getting error: "Uncaught TypeError: Cannot read property 'length' of undefined"出现错误:“未捕获的 TypeError:无法读取未定义的属性‘长度’”
【发布时间】:2015-10-28 05:23:35
【问题描述】:

通过检查 chrome 开发工具提要检索成功和各种字段,如 chrome 开发控制台中显示的 objidpersonidpersonnamepersongroup,我成功地能够使用我的客户端代码从 wsdl 获得响应。但是resultset检索显示错误

未捕获的类型错误:无法读取未定义的属性“长度”

我只需要显示 personid 和 name

main.js

currentPage = {};

currentPage.init = function(){
    WL.Logger.debug("MainPage :: init");
};

function validate(){

    var username=$('#username').val();
    var password=$('#userpwd').val();

    busyIndicator.show();

    var params = {
            "process": {"username":username,"userpwd":password}
    };
        var invocationData = {
                adapter : 'SoapAdapter1',
                procedure : 'userlogin_ep_process',
                parameters : [params]
            };
        //{"process":{"username":"$('#username').val()","userpwd":"$('#userpwd').val()"}}
        WL.Client.invokeProcedure(invocationData,{
            onSuccess : loadFeedsSuccess,
            onFailure : loadFeedsFailure
        });
    }

    function loadFeedsSuccess(result){
        WL.Logger.debug("Feed retrieve success");
        busyIndicator.hide();

    alert(result.responseJSON.Envelope.Body.processResponse.PERSON_ID);
    //alert is priniting the value its working
    displayFeeds(result.responseJSON.Envelope.Body.processResponse);

    }

    function loadFeedsFailure(result){
        WL.Logger.error("Feed retrieve failure");
        busyIndicator.hide();
        WL.SimpleDialog.show("Inquiry", "Service not available. Try again later.", 
                [{
                    text : 'Reload',
                    handler : WL.Client.reloadApp 
                },
                {
                    text: 'Close',
                    handler : function() {}
                }]
            );
    }

        function displayFeeds(result){
            var ul = $('#mytable');
       //here i get length undefined error
            for (var i = 0; i < result.responseJSON.length; i++) {

                var li = $('<li/>').html("PERSONID:" +result[i].PERSONID);
                 li.append($('<li/>').html("PERSONNAME:" +result[i].PERSONNAME));

                 li.append($('<hr>'));
                 ul.append(li);
           }
        }

index.html

<label>username</label> <input type="text" id="username"><br><br>
<label>password</label> <input type="text" id="userpwd"><br><br>
<input type="submit" value="login" onclick="validate();">
<ul id="mytable"></ul>

回复:

{
   "Envelope": {
      "Body": {
         "processResponse": {
            "ERROR_CODE": "S",
            "ERROR_MSG": "Login Successful",
            "GROUPS_ID": "76721",
            "PERSON_ID": "309236",
            "PERSON_LOGIN": "Y",
            "PERSON_NAME": "Welcome! ashanka",
            "PERSON_ROLE": "Y",
            "PERSON_UID": "1014336",
            "client": "http:\/\/xmlns.oracle.com\/InternetMobile\/AbsManagement\/BPELProcessUserLogin",
            "xmlns": "http:\/\/xmlns.oracle.com\/InternetMobile\/AbsManagement\/BPELProcessUserLogin"
         }
      },
      "Header": {
         "FaultTo": {
            "Address": "http:\/\/www.w3.org\/2005\/08\/addressing\/anonymous"
         },
         "MessageID": "urn:C9C4DB207D5211E5BF9B25E60F40847D",
         "ReplyTo": {
            "Address": "http:\/\/www.w3.org\/2005\/08\/addressing\/anonymous"
         }
      },
      "env": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/",
      "wsa": "http:\/\/www.w3.org\/2005\/08\/addressing"
   },
   "errors": [
   ],
   "info": [
   ],
   "isSuccessful": true,
   "responseHeaders": {
      "Content-Length": "1017",
      "Content-Type": "text\/xml; charset=utf-8",
      "Date": "Wed, 28 Oct 2015 09:03:42 GMT",
      "SOAPAction": "\"\"",
      "X-ORACLE-DMS-ECID": "9e10a9dcf92c80fa:-8e91c30:150a34b187a:-8000-0000000000053e79",
      "X-Powered-By": "Servlet\/2.5 JSP\/2.1"
   },
   "responseTime": 106,
   "statusCode": 200,
   "statusReason": "OK",
   "totalTime": 122,
   "warnings": [
   ]
}

【问题讨论】:

  • 听不懂你能不能简单介绍一下????
  • 为您的项目提供可重现错误的地方。将其上传到 Dropbox 或 Google Drive。
  • @IdanAdar 嘿发现了什么???
  • 什么时候可以得到解决方案,我可以再发一次吗

标签: javascript json soap


【解决方案1】:

您收到的对象中没有“responseJSON”,这就是“长度”未定义错误失败的原因:for (var i = 0; i &lt; result.responseJSON.length; i++)。删除 responseJSON 并使用类似:How to get object length 或其他方法。

【讨论】:

  • alert(result.responseJSON.Envelope.Body.processResponse.PERSON_ID) 通过这种方式,只有我可以从响应消息中获取人员 ID,所以我尝试了。即使我从 for 中删除了响应 Json循环我得到长度未定义。但我发现返回响应不是值数组,因为它返回 {} 而不是 [] 所以长度未定义的原因可能会出现,但我没有
  • 是的,它不是一个数组。使用类似:stackoverflow.com/questions/5533192/how-to-get-object-length
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-24
相关资源
最近更新 更多