locked
get data from rest api RRS feed

  • Question

  • User-131059102 posted

    I'm trying to return data from a rest service returning json... I do seem to be getting an object back but I don't understand how I can display those results on my page.

      <input id="btnSubmit" type="submit" value="Release"/>
    <script>
        $(document).ready(function() {
            $("#btnSubmit").click(function(){
                alert("button");
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "http://ebird.org/ws1.1/data/notable/geo/recent?lng=-110.926479&lat=32.221743&dist=2&back=5&maxResults=500&detail=simple&locale=en_US&fmt=json",
                    success: function (result) {
                        $("#div1").html(result);
                        alert("success" + result);
                    },
                    error: function () {
                        alert("Local error callback.");
                    },
                    complete: function () {
                        alert("Local completion callback.");
                    }
                });
            }); 
            
        });
    </script>
        <div id="div1"></div>

    any help is greatly appreciated!

    Thursday, February 25, 2016 6:39 AM

Answers

  • User-131059102 posted

    I got lucky and managed to figure it out... thanks to the clever use of Google... 

        <input id="btnSubmit" type="submit" value="Release" />
        <script>
            $(document).ready(function () {
                $("#btnSubmit").click(function () {
                    alert("button");
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        url: "http://ebird.org/ws1.1/data/notable/geo/recent?lng=-110.926479&lat=32.221743&dist=2&back=5&maxResults=500&detail=simple&locale=en_US&fmt=json",
                        success: function (result) {
                            $("#div1").text(JSON.stringify(result));
                            alert("success" + JSON.stringify(result));
                        },
                        error: function () {
                            alert("Local error callback.");
                        },
                        complete: function () {
                            alert("Local completion callback.");
                        }
                    });
                });
    
            });
        </script>
        <div id="div1"></div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2016 6:50 AM

All replies

  • User-131059102 posted

    I got lucky and managed to figure it out... thanks to the clever use of Google... 

        <input id="btnSubmit" type="submit" value="Release" />
        <script>
            $(document).ready(function () {
                $("#btnSubmit").click(function () {
                    alert("button");
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        url: "http://ebird.org/ws1.1/data/notable/geo/recent?lng=-110.926479&lat=32.221743&dist=2&back=5&maxResults=500&detail=simple&locale=en_US&fmt=json",
                        success: function (result) {
                            $("#div1").text(JSON.stringify(result));
                            alert("success" + JSON.stringify(result));
                        },
                        error: function () {
                            alert("Local error callback.");
                        },
                        complete: function () {
                            alert("Local completion callback.");
                        }
                    });
                });
    
            });
        </script>
        <div id="div1"></div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2016 6:50 AM
  • User61956409 posted

    Hi sayitfast,

    Yes, JSON.stringify() method could convert a JavaScript object to a JSON string. Besides, values in JavaScript objects are written as name:value, you could also to use objects.name to get the value.

    Best Regards,

    Fei Han

    Friday, February 26, 2016 2:14 AM