JS GeoLocation:让$.ajax等待结果

JS GeoLocation: make $.ajax wait for result

本文关键字:ajax 等待 结果 GeoLocation JS      更新时间:2024-04-16

当我向后端发送AJAX POST请求时,我希望从导航器发送纬度和经度。但很明显,在后台,发送请求时甚至没有等待导航器完成。我正在使用Parse库,有没有一种方法可以在收集lat/lon之前暂停请求?

$(document).ready(function(){
    Parse.initialize("xxxxxx", "xxxxxx");
    var Location = Parse.Object.extend("Location");
    var location = new Location();
    location.save({
        latitude: latitude,
        longitude: longitude,
        description: "Testdescription",
        kind: 1
    }).then(function(object){
        alert("YAY, it worked.");
    }, function(err){
        console.log(err);
    });
});

您只需要在位置成功回调中调用ajax请求,如下所示:

功能地理位置处理(位置){//调用您的方法来保存数据}