My webpage is supposed to generating a series of questions in a random order. Each question is a seperate HTML page with a picture and multiple options.On page load, there should a default question and thereafter on clicking next a new page is loaded. I am currently:
I am stuck at the third step; how do you send a json array element in an ajax call i.e.
$.ajax({
url: name+".html",
success: function(html){
$("#container").empty().append(html);
}
});
where name is the name of the webpage stored in the json array and container is the div on my current php page. In case there is an easier way of doing the above task, I am open to that too.
Thanks!
EDIT Step 2:
var xdata = <?php echo json_encode($testArray); ?>;
where $testArray is the php shuffled array of webpages.
Use the jQuery load function.
var pageToLoadIntoContainer = 'Test1.html';
$('#container').load( pageToLoadIntoContainer );
Extending this answer to try and solve all of your elements...
<?php
$pageArray = shuffle(array(
'Test1' ,
'Test2' ,
'Test3'
));
....
?>
<script>
var pageArray = <?php echo json_encode( $pageArray ); ?>;
....
$('#container1').load( pageArray[0] );
$('#container2').load( pageArray[1] );
$('#container3').load( pageArray[2] );
</script>
$.ajax({ url: name+".html", success: function(html)
$("#container").empty().append(html);
}
});
there are 1 '{' and 2 '}' try
$.ajax({ url: name+".html", success: function(html){
$("#container").empty().append(html);
}
});