{"action":"created","issue":{"url":"https://api.github.com/repos/HubSpot/offline/issues/33","labels_url":"https://api.github.com/repos/HubSpot/offline/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/HubSpot/offline/issues/33/comments","events_url":"https://api.github.com/repos/HubSpot/offline/issues/33/events","html_url":"https://github.com/HubSpot/offline/issues/33","id":23751366,"number":33,"title":"Only last XHR request being sent","user":{"login":"thomhines","id":760759,"avatar_url":"https://avatars.githubusercontent.com/u/760759?v=3","gravatar_id":"","url":"https://api.github.com/users/thomhines","html_url":"https://github.com/thomhines","followers_url":"https://api.github.com/users/thomhines/followers","following_url":"https://api.github.com/users/thomhines/following{/other_user}","gists_url":"https://api.github.com/users/thomhines/gists{/gist_id}","starred_url":"https://api.github.com/users/thomhines/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomhines/subscriptions","organizations_url":"https://api.github.com/users/thomhines/orgs","repos_url":"https://api.github.com/users/thomhines/repos","events_url":"https://api.github.com/users/thomhines/events{/privacy}","received_events_url":"https://api.github.com/users/thomhines/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2013-12-04T22:26:22Z","updated_at":"2015-05-19T09:12:46Z","closed_at":null,"body":"When sending multiple XRH requests during a period of no connection, only the last one is being sent to the flush function. I believe that the `requests` array being set on line 53 (of requests.js) is being overwritten with each pass of the for loop. \r\n\r\nTo temporarily fix this on my site, I replaced that line with:\r\n\r\n`makeRequest(request);`\r\n\r\nand removed the second for loop from the function (lines 55-58 of requests.js)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/HubSpot/offline/issues/comments/103410458","html_url":"https://github.com/HubSpot/offline/issues/33#issuecomment-103410458","issue_url":"https://api.github.com/repos/HubSpot/offline/issues/33","id":103410458,"user":{"login":"neilRGS","id":12459731,"avatar_url":"https://avatars.githubusercontent.com/u/12459731?v=3","gravatar_id":"","url":"https://api.github.com/users/neilRGS","html_url":"https://github.com/neilRGS","followers_url":"https://api.github.com/users/neilRGS/followers","following_url":"https://api.github.com/users/neilRGS/following{/other_user}","gists_url":"https://api.github.com/users/neilRGS/gists{/gist_id}","starred_url":"https://api.github.com/users/neilRGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilRGS/subscriptions","organizations_url":"https://api.github.com/users/neilRGS/orgs","repos_url":"https://api.github.com/users/neilRGS/repos","events_url":"https://api.github.com/users/neilRGS/events{/privacy}","received_events_url":"https://api.github.com/users/neilRGS/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T09:12:46Z","updated_at":"2015-05-19T09:12:46Z","body":"Hi Thom.\r\nIt does return all but the last item in the queue.  I have added 1 to the length check in the for loop on line 53, which solves that:\r\n  for (_i = 0, _len = itemsToSend.length+1; _i < _len; _i++) {\r\nI suppose this would also work:\r\n  for (_i = 0, _len = itemsToSend.length; _i <= _len; _i++) {\r\n\r\n\r\nAdditionally, in my implementation, I have added all items in the queue to localstorage.  My reason for that is that should the device power down or go to sleep, the memory may be cleared and the queue lost.\r\nTherefore, instead of the makeRequest() function, I take the data and send it to a separate ajax call instead.\r\n\r\nI will also be creating a CRC32 check so that my web service can send a response and I can compare the checks.  That will ensure that I can guarantee that there won't be any broken data sent back to my webservice.\r\n\r\nIt would be fantastic if a future version could include that functionality (at least, the localStorage part), as ensuring a robust resume from being offline and powered down is quite important IMHO.\r\n\r\nThanks! :-)\r\n\r\n"}}