javascript - How to solve my http request issue? -
this question has reply here:
javascript closure within loops – simple practical example 23 answersi trying resolve issue related http requests.
i need fire multiple http request within loop. loop provides url request. need force project id
array
based loop variable.
var array = []; for(var = 0; < project.length; i++) { var url = project[i].url getprojectdetail(url) .then(function(data) { console.log(i) //this outputs project.length 10 array.push ({id:project[i].id, detail:data.detail}) // error here cannot read property 'id' of undefined } }
it seem request takes time , variable i
max length. not sure how resolve issue. thoughts?
thanks much!
getprojectdetail
returning promise, calling getprojectdetail
within loop. loop not hold until promise resolve means loop not hold until u info getprojectdetail()
, for-loop progress.
javascript angularjs xmlhttprequest
No comments:
Post a Comment