Microsoft Developer Network > Forums Home > Windows Live Developer Forums Forums > Windows Live Search: Development > live search using json not working in ie, works in firefox
Ask a questionAsk a question
 

Questionlive search using json not working in ie, works in firefox

All Replies

  • Tuesday, December 23, 2008 2:45 AMJoePurnell Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I got this example to work in IE, no problem.  Is there any way to check the results from the raw json feed by typing the string in the url of IE? 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html >

    <head>

    <title>Live Search API 2.0 Web Sample</title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <script type="text/javascript">

    // Replace the following string with the AppId you received from the

    // Live Search Developer Center.

    var AppId = "[Your AppId here]";

    // Live Search API 2.0 code sample demonstrating the use of the

    // Web SourceType over the JSON Protocol.

    function Search()

    {

    var requestStr = "http://api.search.live.net/json.aspx?"

    // Common request fields (required)

    + "AppId=" + AppId

    + "&Query=msdn blogs"

    + "&Sources=Web"

    // Common request fields (optional)

    + "&Version=2.0"

    + "&Market=en-us"

    + "&Adult=Moderate"

    + "&Options=EnableHighlighting"

    // Web-specific request fields (optional)

    + "&Web.Count=10"

    + "&Web.Offset=0"

    + "&Web.FileType=DOC"

    + "&Web.Options=DisableHostCollapsing+DisableQueryAlterations"

    // JSON-specific request fields (optional)

    + "&JsonType=callback"

    + "&JsonCallback=SearchCompleted";

    var requestScript = document.createElement("script");

    requestScript.type = "text/javascript";

    requestScript.src=requestStr;

    var head = document.getElementsByTagName("head");

    head[0].appendChild(requestScript);

    }

    function SearchCompleted(response)

    {

    var errors = response.SearchResponse.Errors;

    if (errors != null)

    {

    // There are errors in the response. Display error details.

    DisplayErrors(errors);

    }

    else

    {

    // There were no errors in the response. Display the

    // Web results.

    DisplayResults(response);

    }

    }

    function DisplayResults(response)

    {

    var output = document.getElementById("output");

    var resultsHeader = document.createElement("h4");

    var resultsList = document.createElement("ul");

    output.appendChild(resultsHeader);

    output.appendChild(resultsList);

    var results = response.SearchResponse.Web.Results;

    // Display the results header.

    resultsHeader.innerHTML = "Live Search API Version "

    + response.SearchResponse.Version

    + "<br />Web results for "

    + response.SearchResponse.Query.SearchTerms

    + "<br />Displaying "

    + (response.SearchResponse.Web.Offset + 1)

    + " to "

    + (response.SearchResponse.Web.Offset + results.length)

    + " of "

    + response.SearchResponse.Web.Total

    + " results<br />";

    // Display the Web results.

    var resultsListItem = null;

    var resultStr = "";

    for (var i = 0; i < results.length; ++i)

    {

    resultsListItem = document.createElement("li");

    resultsList.appendChild(resultsListItem);

    resultStr = "<a href=\""

    + results[i].Url

    + "\">"

    + results[i].Title

    + "</a><br />"

    + results[i].Description

    + "<br />Last Crawled: "

    + results[i].DateTime

    + "<br /><br />";

    // Replace highlighting characters with strong tags.

    resultsListItem.innerHTML = ReplaceHighlightingCharacters(

    resultStr,

    "<strong>",

    "</strong>");

    }

    }

    function ReplaceHighlightingCharacters(text, beginStr, endStr)

    {

    // Replace all occurrences of U+E000 (begin highlighting) with

    // beginStr. Replace all occurrences of U+E001 (end highlighting)

    // with endStr.

    var regexBegin = new RegExp("\uE000", "g");

    var regexEnd = new RegExp("\uE001", "g");

    return text.replace(regexBegin, beginStr).replace(regexEnd, endStr);

    }

    function DisplayErrors(errors)

    {

    var output = document.getElementById("output");

    var errorsHeader = document.createElement("h4");

    var errorsList = document.createElement("ul");

    output.appendChild(errorsHeader);

    output.appendChild(errorsList);

    // Iterate over the list of errors and display error details.

    errorsHeader.innerHTML = "Errors:";

    var errorsListItem = null;

    for (var i = 0; i < errors.length; ++i)

    {

    errorsListItem = document.createElement("li");

    errorsList.appendChild(errorsListItem);

    errorsListItem.innerHTML = "";

    for (var errorDetail in errors[i])

    {

    errorsListItem.innerHTML += errorDetail

    + ": "

    + errors[i][errorDetail]

    + "<br />";

    }

    errorsListItem.innerHTML += "<br />";

    }

    }

    </script>

    </head>

    <body onload="Search()">

    <div id="output"></div>

    </body>

    </html>


    Joe