I'm making multiple ajax request by encapsulate in a for-loop:
for(var o = 1; o <= 2; o++)
{
$.ajax({
type: 'GET',
url: 'lib/terrain.php',
dataType: 'html',
data: {o: o},
success: function(data) {
var objectRuta = Math.floor((Math.random() * 100) + 1); //Slumpar tal mellan 1 & 100
angular.element('.click#'+objectRuta).addClass('object').html($("<img src='images/potion.png' title='"+data+"'>"));
console.log(data);
},
error: function(xhr, ajaxOptions, thrownError) { alert(thrownError); }
});
k=o;
}
This get's information about different objects from my backend:
if(isset($_GET['o']))
{
$object_query = mysql_query("SELECT * FROM objects");
$objects = array();
while($object_row = mysql_fetch_row($object_query))
{
$objects[] = $object_row; //Information about objects
}
$count_objects = count($objects); //Count how many objects it is
$slump_objects = rand(1, $count_objects); //Sell of which objects that shoul be viewd at the map.
var_dump($objects[$slump_objects]);
}
As you can see, I'm making the ajax-call to my backend twice. The problem I have is that sometimes it only get ONE value from my backend, instead of two. Sometimes it get's both the values, which is correct. BUt the problem is that sometimes it only get's one value, and the other value is NULL.
Why is that?