I've wrote just a simple script, to collect some data and send it aftertwards via AJAX to an import script of my rails application.
After I didn't get any data, I've used the chrome debugger, but I still don't find the problem.
$('#poi_import').on('click',function () {
var token = $('.temp_information').data('token');
var auth_token = $('.temp_information').data('auth-token')
poi = [];
$('#service-helper input[type="checkbox"]:checked').each( function(element){
var request = {
placeId: $(this).attr('id')
};
var detail_service = new google.maps.places.PlacesService($('#tmp').get(0));
detail_service.getDetails(request, function(place, _status) {
write_poi(place);
});
});
console.log("Now send the data")
console.log(poi)
jQuery.ajax({
url: "/api/" + token + "/import",
data: poi,
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader('AUTHTOKEN', auth_token);
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
}
});
function write_poi(place) {
//getting some information from "place"
poi.push({
'name': name,
'address': street,
'city': city,
'country': country,
'phone': phone,
'url': url
});
console.log(poi)
}
The console is logging followig lines:
Now send the data
[]
[Object]
[Object, Object]
[Object, Object, Object]
The script do the AJAX request, at first. After that it iterates the checked checkboxes...