Question T10305
Visible to All Users

Multiple SendResult issues

created 2 years ago (modified 2 years ago)

I want to send the data through the loop. Like i am running a loop to store the data into the server not stored due to lack of internet connectivity and which is in indexedDB of a browser.
While running loop when i try to store the data in the loop like

Code
for (let Data of request.result){ survey.data = sData delRespID = sData.RespID survey.sendResult({PostID}) };

Then there is onsendresult function where i am checking if the data has been successfully sent to the server then want to delete those
records from IndexedDB in the browser.

Code
survey.onSendResult.add(function (survey, options) { if(options.success===true){ deleteData(delRespID); } });

But the problem i am facing is, the loop gets executed first for all the records and then it executes this onsendresult function due to which i am facing problem to fetch the ids to delete from indexedDB. So, my query is how can i execute this onsendresult function immediately after each record is sent to the server.

Answers approved by surveyjs Support

created 2 years ago

Hello,

I can not clearly understand your goals (why are you sending data in loop?) but I can say that onSendResult event is firing in XMLHttpRequest.onload callback. If you call sendResult within loop, onSendResult will be fired in next time frames.

I think that if you want call onSendResult after each sendResult you may need to do it recursively: send first data packet and then send next data packet in onSendResult event, and so on up to the end.

Thank you,
Alex
SurveyJS Team