我想發送一個數組與ajax到PHP。有人請 建議一種方法來實現它?如何發送數組javascript到PHP?
我的代碼:
guardarRuta: function(){
console.log('Guardando ruta...');
for (var i = 0; i < marcadores.length; i++) {
latLngMarcadores.push({'tipo': 'parada', 'latitud': marcadores[i].position.lat(), 'longitud': marcadores[i].position.lng()});
}
latLngOrigenDestino.push({'tipo': origenDestino[0].tipo, 'latitud': origenDestino[0].marker.position.lat(), 'longitud': origenDestino[0].marker.position.lng()});
latLngOrigenDestino.push({'tipo': origenDestino[1].tipo, 'latitud': origenDestino[1].marker.position.lat(), 'longitud': origenDestino[1].marker.position.lng()});
Ext.Ajax.request({
url: 'http://becea.mx/dabbawalas_valeria/adm/save_route_adm.php',
method: 'POST',
params: {
nombre: 'RutaNueva',
data: {"marcas" : JSON.stringify(latLngMarcadores)},
},
reader: {
type: 'json',
rootProperty: 'status'
},
success: function(response) {
//Ext.Viewport.setMasked(false);
Ext.Msg.alert('Listo', 'Ruta guardada con éxito!');
},
failure: function() {
//Ext.Viewport.setMasked(false);
Ext.Msg.alert('ERROR', 'Error de servidor');
}
});
}
<?php
$elements = json_decode($_POST['marcas']);
echo($elements[0]);
?>
<?php $ elements = json_decode($ _ POST ['marcas']); echo($ elements [0]); ?> –
你還沒有用JSON.stringify(latLngMarcadores)發送,發送如下數據:{「marcas」:latLngMarcadores} –
這些方法會將json或數組在php中? –