locked
jquery problem post more time RRS feed

  • Question

  • User932259438 posted

    Hi,

    I need to alert two different data with my code but I don't have idea how to do this.

        <script>
            // A $( document ).ready() block.
            $(document).ready(function () {
    
                var latlon = "45.9606152,13.641309 - 47.8006152,15.641309 ";
               // var lon = "13.641309";
    
                $.ajax({
                    type: "POST",
                    url: ("https://nominatim.openstreetmap.org/reverse.php?lat=45.9606152&lon=13.641309&zoom=16&format=json").replace("45.9606152",lat).replace("13.641309",lon),
                    contentType: "application/json",
                    success: function(msg){
                        alert(JSON.stringify(msg));
                    }
                })
            });
        </script>

    From my database I have like this: 

    var latlon = "45.9606152,13.641309 - 47.8006152,15.641309 "

    Reverse is separate with "-" In my case I need to post two times, and display two alert for each data.

    Thursday, January 9, 2020 8:38 AM

All replies

  • User1535942433 posted

    Hi progy85,

    Accroding to your codes,I suggest you could loop the ajax and set two variables of "lat" and "lon".Then you could assign the value of the item variable to two data.

    Since I don't know your url,so I creat a little test for you.

    More details,you could refer to below codes:

    <script type="text/javascript">
            $(document).ready(function () {
                var lat = '';
                var lon = '';
                var value = [
                    {
                        "lat": "45.9606152",
                        "lon": "13.641309",
                    },
                    {
                        "lat": "47.8006152",
                        "lon": "15.641309",
                    }
                ];
                $.each(value, function (i, item) {
                    $.ajax({
                        type: "POST",
                        url: ("https://nominatim.openstreetmap.org/reverse.php?lat=" + item.lat + "&lon=" + item.lon + "&zoom=16&format=json"),
                        contentType: "application/json",
                        success: function (data) {
                            alert(item.lat + "," + item.lon);
                            alert(JSON.stringify(data));
                        },
    
                    });
    
                });
            });
        </script>

    Best regards,

    Yijing Sun

    Friday, January 10, 2020 8:17 AM