Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:20:44+00:00 2026-05-28T16:20:44+00:00

The following is the example from the MSDN website example for JSON with bing

  • 0

The following is the example from the MSDN website example for JSON with bing

I can get alert0 but this example doesn’t call the callback.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Bing API 2.0 Web Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script id="searchCallback" type="text/javascript" src=""></script>

<script type="text/javascript">


// Replace the following string with the AppId you received from the
// Bing Developer Center.
var AppId = "SOME APP ID HERE";

// Bing API 2.0 code sample demonstrating the use of the
// Web SourceType over the JSON Protocol.
function Search()
{

    var requestStr = "http://api.bing.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.Options=DisableHostCollapsing+DisableQueryAlterations"

        // JSON-specific request fields (optional)
        + "&JsonType=callback"
        + "&JsonCallback=SearchCompleted";

     var requestScript = document.getElementById("searchCallback");
     requestScript.src = requestStr;
    alert("0");
}

function SearchCompleted(response)
{
alert("1");
    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)
{
alert("2");
    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 = "Bing 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)
{
alert("3");
    // 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)
{
alert("4");
    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()">
Bing api test
<div id="output"></div>
</body>
 <script id="searchCallback" type="text/javascript" src=""></script>

</html>

if I manually request the requestStr I can get a response:

if(typeof SearchCompleted == 'function') SearchCompleted({"SearchResponse":{"Version":"2.0","Query":{"SearchTerms":"msdn blogs"},"Web":{"Total":2,"Offset":0,"Results":[{"Title":"MSDN Blogs","Description":"Integrated blog from the Microsoft Developer Network.","Url":"http:\/\/blogs.msdn.com\/","DisplayUrl":"blogs.msdn.com","DateTime":"2012-01-09T22:59:00Z"},{"Title":"Remote Desktop Services (Terminal Services) Team Blog - Site Home ...","Description":"All postings, articles, and other content on this blog are provided ”AS IS” with with no warranties, and confer no rights. Any code, demo, or sample on this blog ...","Url":"http:\/\/blogs.msdn.com\/b\/rds\/","DisplayUrl":"blogs.msdn.com\/b\/rds","DateTime":"2012-01-11T17:59:00Z"}]}}} /* pageview_candidate */);

I cant see how the request gets executed after it get’s put into the “searchCallback” src

I’ve tried IE9 FF and Chrome, all not working 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:20:45+00:00Added an answer on May 28, 2026 at 4:20 pm

    The request doesnt start if you just change the source of an existing element. Try the following, replacing the lines:

    var requestScript = document.getElementById("searchCallback");
    requestScript.src = requestStr;
    

    With:

    var commScript = document.createElement("script");
    commScript.src = requestStr;
    commScript.type = "text/javascript";
    commScript.charset = "UTF-8";
    //Find the head element such that we can append our communication script  
    if(document.head)
    {
       head = document.head;
    }
    else if(document.getElementsByTagName)
    {
      head = document.getElementsByTagName('head')[0];
    }
    else
    {
      document.write("An error occured");
    }
    head.appendChild(commScript);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This following code example is borrowed from MSDN here . I am not getting
Can someone please derive a concrete example from the following: http://www.urdalen.com/blog/?p=210 ..that shows how
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
The following MSDN example promises to demonstrate how to use the .NET BackgroundWorker from
I'm trying to implement an encrypted column as in this following MSDN example .
Look at the following example (partially taken from MSDN Blog ): class Animal {
This is an Example from MSDN about Object Class in .NET FrameWork. using namespace
This may well have come up before but the following code is taken from
I am following instructions from this MSDN article: How to: Sort a GridView Column
I see an example from the website http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser%28v=VS.90%29.aspx Here they are using a statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.