Answered Regarding Bing search

  • Tuesday, December 18, 2012 11:47 AM
     
     

    I am trying to access/search the images from the bing search but i am not able to get kindly anyone can help me.the php code is below:

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
     

    <title>Using Bing and JSON</title>
    <script type="text/javascript">

    var AppId = "9Q6KDQqTicdxo7gO3neaxnoozeEN1DYG67vLVffIeRs=";
    var serviceURI ="http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sources=image";
    function search() {
        
    var search = "&query=" + document.getElementById("searchText").value;
    alert(AppId);
    var fullUri = serviceURI + AppId + search;
    var head = document.getElementsByTagName('head');
    var script = document.createElement('script');
    script.type = "text/javascript";
    script.src = fullUri;
    alert(script.src);
    head[0].appendChild(script);
    }
    function searchDone(results) {
        alert(results);
    var result = null;
    var parent = document.getElementById('resultList');
    parent.innerHTML = '';
    var child = null;
    child = document.createElement('li');
    child.className = "resultlistitem";

    for (var i = 0; i < results.SearchResponse.Image.Results.length; i++) {
    result = results.SearchResponse.Image.Results[i];
    //child = document.createElement('li');
    //child.className = "resultlistitem";
    parent.innerHTML = '<a href="' + result.Url +'"><img src="' +
    result.Thumbnail.Url +'" alt="' + result.Title +'" /></a>';
    parent.innerHTML = '<p> this is now clicked</p>';
    alert(result.Thumbnail.Url);
    //parent.appendChild(child);
    }
    }
    </script>
    </head>
    <body>
    Type in a search:<input type="text" id="searchText" value="sushi"/>
    <input type="button" value="Search!" id="searchButton" onClick="search()" />
    <div ID="resultList" style="border:thin solid #8A8A8A">
     
    </div>
    </body>
    </html>

    Here i am not getting any response from bing and getting javascript error like

     results.SearchResponse.Image is undefined

    • Edited by CHETHAN KV Tuesday, December 18, 2012 12:01 PM
    •  

All Replies