I want to add point on image, so I use ajax to get data, but in following code, I use map_add_beacon();
to send request, I's all right until .done(function (beacondata)
, I want this code execute before data.push( { x: 300, y: 300, text: 'test point1' });
, but .done(function (beacondata)
real execute is after var Taggd = function(element, options, data)
finished, how can I let ajax quickly execute?
Thanks!
var Taggd = function(element, options, data) {
var _this = this;
if(options.edit) {
options.handlers =
{
click: function() {
_this.hide();
methods.show.call(this);
}
};
}
this.element = $(element);
this.options = $.extend(true, {}, defaults, options);
this.data = data;
map_add_beacon();
data.push( { x: 300, y: 300, text: 'test point1' });
data.push( { x: 300, y: 400, text: 'test point2' });
this.initialized = true;
if(!this.element.height() || !this.element.width()) {
this.element.on('load', _this.initialize.bind(this));
}
else this.initialize();
};
function map_add_beacon(){
var request = "/maps/map_beacon_assigned?locate_id=1" //access controller of interest
//+ $('#uninstall_brand_id_select').val();
var aj = $.ajax({
url: request,
type: 'get',
beacondata: $(this).serialize()
}).done(function (beacondata) {
insert_beacon(beacondata);//modify the majors' dropdown
}).fail(function (beacondata) {
console.log('AJAX request has FAILED');
});
};
function insert_beacon(beacondata){
for(var i=0;i<beacondata.length;i++){
data.push( { x: beacondata[i][0], y: beacondata[i][1], text: beacondata[i][2] });
};
};