javascript - Uncaught TypeError: Cannot use ‘in’ operator to search for ‘length’ in jquery-1.11.1.js:583 -


i have 2 js files shown below (page1.js) , (page2.js reference included below). referring following json response while working :

{     "webservice_status": {         "status": "success",         "message": ""     },      "my_document_list": [{              "doc1": "445",             "doc2": "445",             "doc3": "445",             "doc4": "445",             "content": "some text here display"         }      ] } 

here page1.js related work:

$("#mydoclist").on('rowclick', function (event) {             row = event.args.rowindex;             datarow = $("#mydoclist").jqxgrid('getrowdata', row);             var response = json.stringify(datarow, null, 10);             var docid  = datarow["doc_id"];             self.getmydocumentcontents(docid);     });  this.getmydocumentcontents = function (contentid_) {     var data = {       doc_id: contentid_    }     app_.get(data, self.processcontent, app_.processerror, url_name);  }// end of getmydocumentcontents   this.processcontent = function(data_,textstatus_,jqxhr_) {        data_ = app_.convertresponse(data_,jqxhr_);       console.log("checking actual data_ content:", data_);        console.log("actual data length check data_ content:", data_.my_document_list.length);         // debugger;        var collection = data_.my_document_list.length[0].content;       console.log("collection check",collection);        //debugger;         var source = {          localdata: collection,          datafields: [{          name: 'content',          type: 'string'        }],       datatype: "array"       };         var dataadapter = new $.jqx.dataadapter(source, {             loadcomplete: function (records) {                  debugger;                  var html;            //get data             var records = dataadapter.records;             console.log("check records:",records.length);             var length = records.length;             html = "<div style='margin: 10px;'><pre>" + records[0].content + "</pre></div>";             $("#doccontentpanel").jqxpanel('clearcontent');             $("#doccontentpanel").jqxpanel('append',html);              },             loaderror: function (xhr, status, error) { },             beforeloadcomplete: function (records) {              }             });              // perform data binding             dataadapter.databind();              var panel = $("#doccontentpanel");             var content = panel.html();             panel.jqxpanel({ width: '750', height: '500', scrollbarsize: 20 });   }// end of processcontent 

here page2.js related work:

this.get = function (data_, done_, fail_, webservicekey_) {          // lookup requested web service url         var url = https://documentlookup.com:8443/getmydocuments;           // create ajax request.         $_.ajax({             data: data_,             method: "get",             url: url         })         .success(done_)         .error(fail_);     };  // if json data returned content type of "text/plain", parse json before returning.     this.convertresponse = function (data_, jqxhr_) {          return (typeof(data_) === "object" ? data_ : json.parse(data_));      }; 

basically there list of rows displayed in jqxgrid(not mentioned in code above), when user clicks on $("#mydoclist").on('rowclick gets called , calls following function: getmydocumentcontents function: function passes doc_id inside data variable made available following function: processcontent: in function, trying show in jqxpanel value of contentwhich in my_document_list array.

problem facing inside function: can seen, there debugger placed @ various places commented except @ 1 place below line loadcomplete: function (records) { don’t error above line var dataadapter = new $.jqx.dataadapter(source, { , however, place inside it, following error:

uncaught typeerror: cannot use ‘in’ operator search ‘length’ in jquery-1.11.1.js:583

where length numerical number keeps on changing depending upon length of value of content in above json response. tell me what’s going wrong? in advance ! in case needed, here jquery line #583 isarraylike function :

function isarraylike( obj ) {     var length = obj.length,         type = jquery.type( obj );      if ( type === "function" || jquery.iswindow( obj ) ) {         return false;     }      if ( obj.nodetype === 1 && length ) {         return true;     }      return type === "array" || length === 0 ||         typeof length === "number" && length > 0 && ( length - 1 ) in obj; // line 583 throws error } 

should try changing jquery version?

at data_.my_document_list.length[0].content; think need data_.my_document_list[0].content;.

my_document_list array , such array access should occur there.


Comments