scoreBoard.push({
acertosOuErros: acertoOuErro,
multiplicacao: resultado
});
This is my array made in javascript, I wanted to pass this array of objects to another page so I would handle it (I would put a results table), I saw that there are several methods (via cookie, via url, via form in hidden), but wanted to know how to send it via ajax (I think that's the best way, is not it?). Could you teach me? I want to learn.
I saw a tutorial elsewhere, but I did not quite understand it.
This Array (dataString) is the example mounted by the site. Javascript:
$(document).ready(function(){
$('a').on('click',function(){
var dataString = {
'id':'1',
'name':'peter parker',
'age':'unknown',
'role':'spiderman'
}
$.ajax({
url: "result.php",
data: {'data':dataString},
type: "POST",
cache: false,
success: function(response){
alert("ok");
$('#test').html(response);
}
});
})
})
HTML:
<a href="javascript:void(0);">Click Me</a>
<div id="test"></div>
result.php
$data = ($_POST['data']);
foreach($data as $d){
echo stripslashes($d);
}
In this example, the array is sent via ajax to result.php, and is a string returned to the previous page? And how do I send my array of objects to another page? I would mount a table with this array sent from the previous page ...