How can I pass variables in loop to a PHP file using AJAX?
var lat;
var lng;
var array = [ 22.399602, 114.041176, 22.344043, 114.0168, 22.327529, 114.087181 ];
console.log(array);
for (var i = 0; i < 6; i += 2) {
lat = array[i];
console.log("lat" + i + "=" + lat);
for(var j = i + 1; j <= i + 1; j++) {
lng = array[j];
console.log("lng" + j + "=" + lng);
}
}
My array is here:
In this case I want pass each lat
and long
to my database. My database will looks like this:
username: Neo
lat=22.399602
long=114.041176
lat=22.344043
long=114.0168
lat=22.327529
long=114.087181
I also test this AJAX function but it isn't working for an array.
$.post('send.php', { latitude: lat, longitude: lng }, function(data) {
$('#result').html(data);
});
What should I do now?
for(var j=i+1; j<=i+1;j++)
what's this for$.post()
give you?