javascript - how to turn loop (for) into promise in java script -
i have implement java script request data server using ajax (xhr).
but somehow, loop not promise.
i tried implement promise alway failed.
this javascript want convert promise
var resula = ajaxa(a); for(resulta){ var resultb = ajaxb(url?param1=resulta.id); for(resultb){ var resultc = ajaxc(url?param1=resulta.id¶m2=resultb.id); for(resultc){ } } }
could please give me guide how turn javascript above promise ??
edited: here java script want use promise
var xhr = $.getjson('${pagecontext.request.contextpath}/someurl.action?'); console.log("after load ajax"); xhr.done(function(data){ (var = 0; < data.length; i++) { var xhrpolygon = $.getjson('${pagecontext.request.contextpath}/koordinat/getkoordinateaja.action?idarea='+data[i].id); xhrpolygon.done(function(resultdata){ if(resultdata.length>0){ (var j = 0; j < resultdata.length; j++) { var koordinat = [resultdata[j].arealng,resultdata[j].arealat]; console.log(koordinat); } } }); } });
javascript xhr isn't build on top of promises, new fetch here have documentation https://github.github.io/fetch/
if need create promise here have code
let promise = new promise((resolve, reject) => { if(success){ resolve(); } else{ reject() } }); promise.then(r => console.log(r), e => console.log(e));
Comments
Post a Comment