The problem is really with naming variables with consecutive IDs (Turret0, Turret1, etc.). This transforms structural information into naming convention, which is of course less convenient to use.
Instead, you should return an array of Turrets in your AJAX response, and access it through turrets[i]
in the loop.