1
I’m having some problems solving this situation. I’m trying to pass my object array via AJAX to another PHP page and read the properties that are inside each object within that array. For you to try to understand better I will post the code here...
My Javascript is mounting the object and returning this data (example values):
[{"horario":"14:00","id_bus_rota_parada":"1","id_bus_rota":"0","id_bus_parada":"22"},{"horario":"15:00","id_bus_rota_parada":"1","id_bus_rota":"0","id_bus_parada":"23"}];
These objects are inside the "data array[]"...
So I try to pass this array of objects to PHP already transformed into JSON.
$.ajax({
url: "../actions/rota_inserir.php",
type: "post",
contentType: 'application/json',
data: JSON.stringify(dados),
dataType: 'json',
success: function (data) {
if (data.sucesso == true) {
var n = noty({
text: "Rota cadastrada com sucesso!",
type: 'success'
});
}
},
});
Now I don’t know how to receive this data in PHP, I did a line of code but it didn’t work...
$horarioParada = $_POST['horario'];
Ah, if I try to visualize the object by the browser using data[0]. id_bus_stop for example, it returns the value correctly.
– Matheus Cavallini
The Ajax date attribute must be an object is not a string!
– Maurivan
Ta, and how I would read the properties of the object in PHP, instead of using $scheduleParada = $_POST['horario'];
– Matheus Cavallini
I see that your script is assembling an array with 2 objects and you want to insert the data of these objects massively! Is that right? In the example, there are 2 objects, can be more or only 2 in all situations?
– Maurivan