locked
Displaying Bing JSON Results W/ Jquery RRS feed

  • Question

  • I have a code sample below that is unfinished.  I can get it to kick out the html blob, but I want to parse and display the JSON text as links and text.  Can someone point me to an example?

    thanks in Advance,

    Rip

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            var params = {
                // Request parameters
    "_type" : "SearchResponse",
    "WebPages" : "True",
                "q": "<cfoutput>#q#</cfoutput>",
                "count": "10",
                "offset": "0",
                "mkt": "en-us",
    "customconfig": "1xxxxxxxx8",
                "safesearch": "Moderate",
    "SearchResponse": "WebPages",
            };

            $.ajax({
                url: "https://api.cognitive.microsoft.com/bingcustomsearch/v5.0/search?" + $.param(params),
                beforeSend: function(xhrObj){
                    // Request headers
                    xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","dxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7");
                },
                type: "GET",
    dataType: "json",
                // Request body

            })
            .success(function(data) {


    if(data.length) 
    {
    alert("data has length");
    $('#results').html(data);
    } else

    {
    alert("data has no length"); }
    })


            .fail(function() {
                alert("error");
    });

        });
    </script>
    <body>
    <h2>Check out the following Results:</h2>
    <div id="results">Results Should be here!</div>

    <cfelse>
    <div style="width: 500px; margin:auto;">
    <h1>Bing Search</h1>
    <form method="post">
    <div align="center">
    <input type="text" name="q"><input type="submit" size="35"></form>
    </div>
    </cfif>

    </body>
    </html>

                              
    • Edited by Rip Casdorph Wednesday, October 11, 2017 10:56 PM
    Wednesday, October 11, 2017 10:55 PM