0

System ignore my first $.get function and go to the second $.get function. I do test in Postman, it's working fine with https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=10.817841669295166&lon=106.64377723626976. I try to catch this function, but no alert, no console log result. I don't know how.

Here's my code:

$('.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>

Update: I got response from the server. I put 5 console log with one missing. enter image description here

enter image description here

enter image description here

kaya3
  • 47,440
  • 4
  • 68
  • 97
  • 1
    Open the Network tab in Google Dev Tools and there you can check if your code is receiving response from the server. Afterwards, provide the information of success/error here. I will try to help – dragomirik Aug 20 '21 at 05:44
  • 1
    Also I made you a snippet. If the server allows CORS from stackoverflow, please add relevant HTML and jQuery version to make a [mcve] – mplungjan Aug 20 '21 at 05:45
  • 1
    Unfortunately, I cannot run it because there are no jQuery connected, you can try it by yourself. Even if you add jQuery in HTML section, there could be different result in your local server or where you are testing, so why information from your device required. – dragomirik Aug 20 '21 at 05:47
  • 1
    Added a button, but for me, `navigator.geolocation.getCurrentPosition` never returns – freedomn-m Aug 20 '21 at 09:00
  • @dragomirik I received response from the server. I'm a new guy, I don't know how to upload image to this comment. So, I'll update in post. – Duy Khương Aug 20 '21 at 09:50
  • @freedomn-m it's working for me. I got all 3 console logs, but lost in fourth log, and if I put a console log in second $.get, I'll get it. – Duy Khương Aug 20 '21 at 09:52
  • FYI you can't put images in comments. – freedomn-m Aug 20 '21 at 09:54
  • I updated my post, I received response from server. – Duy Khương Aug 20 '21 at 10:06

0 Answers0