简体   繁体   English

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

[英]Getting error: "Uncaught TypeError: Cannot read property 'length' of undefined"

i am successfully able to get response from wsdl using my client side code by checking chrome dev tool feed retrieve success and various fields like objid , personid , personname , persongroup displayed in chrome dev console.我是能够成功通过检查Chrome浏览器开发工具使用饲料我的客户端代码从WSDL响应获取成功和各领域一样objidpersonidpersonnamepersongroup在Chrome浏览器开发控制台中显示。 but resultset retrieval is displayed with the errorresultset检索显示错误

Uncaught TypeError: Cannot read property 'length' of undefined"未捕获的类型错误:无法读取未定义的属性“长度””

i need only personid and name to be displayed我只需要显示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索引.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>

The response:响应:

{
   "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": [
   ]
}

There is no "responseJSON" in the object that you have receive, and this is why the error is failing on "length" is undefined: for (var i = 0; i < result.responseJSON.length; i++) .您收到的对象中没有“responseJSON”,这就是错误在“length”未定义时失败的原因: for (var i = 0; i < result.responseJSON.length; i++) Remove responseJSON and use something like: How to get object length or a different approach.删除 responseJSON 并使用类似的内容: How to get object length or a different approach。

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

相关问题 错误 - &#39;&#39;Uncaught TypeError:无法读取属性&#39;length&#39;?未定义&#39;&#39; - Error - ''Uncaught TypeError: Cannot read property 'length"? of undefined'' 未捕获的TypeError:无法读取未定义的属性“长度” - Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“ length” - Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“ length” - Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“ length” - Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“长度” - Uncaught TypeError: Cannot read property 'length' of undefined Uncaught TypeError:无法读取未定义的属性“ length”…? - Uncaught TypeError: Cannot read property 'length' of undefined…? 未捕获的类型错误:无法读取未定义的属性“长度” - Uncaught TypeError : Cannot read property 'length' of undefined Uncaught TypeError:无法读取未定义的属性“ length”? - Uncaught TypeError: Cannot read property 'length' of undefined? 未捕获的TypeError:无法读取未定义的属性“长度”(…) - Uncaught TypeError: Cannot read property 'length' of undefined(…)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM