javascript - Angular http response length undefined -


i'm using angular interact jquery mobile , create several pages running issue $http service when connecting json requests. have few arrays i'm populating functions , can bring data pages, except @ times errors

cannot read property 'length' of undefined

my code looks this:

$http.jsonp(url).success(function(data) {   (i=0; i<data.project.length; i++)       $scope.projectlist.push( { id:data.project[i].project_code, name:data.project[i].project_desc } ); }); 

my loop randomly crash. i've tried "then" approach:

var request = $http.jsonp(url); return request.then(function(request) { return request.data.project; }, handleerror ); 

same error (or no error , blank results). doing wrong? have each api call in it's own function shouldn't reusing objects (might appending them though?). part 1; part 2 separating code controller/service - i'm getting these same errors when well.

update

i've created jsfiddle here showing how values populate - run few times , you'll notice arrays take turns returning empty. if able see console.log output see projectlist contains resultset of equiplist (in addition projectlist) , vice versa.

sorry doesn't let me comment yet :-s i'll answer here. based on

... except at times errors this

it sounds url calling isn't responding correctly. code looks assuming json response looks this:

{   "project": [      { "project_code": ..., "project_desc": ... },     ...   ] } 

however if have intermittently guess server responds other structure above, still sending http status 200 ok.

try monitor network requests , see actual response is, or console.log of data inside success function.

--- edit

as thought api issue. api seems respond correct list(s), times (at least now) responding http 200 ok, without data (content-length: 0). fiddle doesn't show when it's loading, updated code little bit here: http://jsfiddle.net/gce4ns9a/15/. reason why never have 'this never shows up' because api responds 'ok' instead of error code such http 500 inter server error or similar.

i hope helps.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -