我有这种向服务器发送数据的方法:
var points = [];
var coords = polyline.geometry.getCoordinates();
for (var i = 0; i < coords.length; i++)
{
var x = (coords[i][0]).toFixed(4);
var y = (coords[i][1]).toFixed(4);
points[i] = [x,y];
}
$("form").on('submit',
function(e){
var data = $(this).serializeArray();
console.log(points);
data.push({name:'points[]',value:points});
$.ajax(
{
url: '/admin/index/add-route',
method: 'post',
data: data,
success: function(result) {
console.log('succcess');
}
}
);
console.log(data);
e.preventDefault();
return false;
}
);
在后端,我获得了一个包含这些值的一维数组:
(var dump of $_POST['points'])
array (size=1) 0 => string '48.9225,24.6948,48.9220,24.7090' (length=31)