Interrupted ajax call by app switch to inactive handling

when ajax posts a data to server (consider a picture of 3MB), and user switches off the app (becomes inactive) for few seconds… and switches back…

What is a proper way to handle such scenario for an actively running ajax post request.
we noticed un predictable results where return would sometime comeback and be caught by js in other cases not, so we stop requests on app switch and restart on active switch, but that seem to made situation worse, were in some cases we send dups.

i realize this q may not be framework related but more of design/architecture but any advise on best pattern to use in this case would be much appreciated.