系统忽略我的第一个 $.get 函数并转到第二个 $.get 函数。我在 Postman 中进行测试,它与https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=10.817841669295166&lon=106.64377723626976
. 我试图捕捉这个功能,但没有警报,没有控制台日志结果。我不知道怎么做。
这是我的代码:
$('.btncheckin').click(function() {
console.log("button click");
var btnid = $(this).attr('id');
if (navigator.geolocation) {
console.log("has navigator.geolocation");
navigator.geolocation.getCurrentPosition(function(position) {
console.log("got current position, position");
var address = "";
$.get("https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=10.817841669295166&lon=106.64377723626976", function(data1) {
console.log("has address info"); // new update
})
$.get("https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=" + position.coords.latitude + "&longitude=" + position.coords.longitude + "&localityLanguage=vi", function(data) {
var time = 0;
var dd = 0;
var mm = 0;
var yyyy = 0;
console.log("got current latitude, longitude"); //new update
$.ajax({
url: '/Home/CheckIN?EmployeeCode=' + $("#msnv").val() + '&EmployeeIDNo=' + $("#cmnd").val() + '&Latitude=' + data.latitude + '&Longitude=' + data.longitude + '&CheckType=' + CheckType + '&Address=' + address,
type: 'GET',
contentType: 'application/json; charset=utf-8',
success: function(data) {
if (data.IsSuccess)
(
$("#success").removeAttr("style"),
$("#index").attr("style", "display: none !important"),
$("#ggmap").attr("href", data.urlweb),
$("#frame").attr("src", "https://www.google.com/maps/embed/v1/place?q=" + data.Latitude + "," + data.Longitude + "&key=[Mykey]"),
time = +data.CheckDate.replace(/\D/g, ""),
dd = String(new Date(time).getDate()).padStart(2, '0'),
mm = String(new Date(time).getMonth() + 1).padStart(2, '0'), //January is 0!
yyyy = new Date(time).getFullYear(),
$("#timecheckin").text(dd + "/" + mm + "/" + yyyy + " " + new Date(time).getHours() + ":" + new Date(time).getMinutes())
)
}
})
})
});
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class='btncheckin' id='btn'>click me</button>