none
Newbie q: sample html page to seach my site

    Question

  • Hello,

    in asp.net site (sharepoint 2007) I want to add search page that will uses Bing.

    Nothing fancy, no asp.net programming, a little javascript and the results.

    Could anyone point me to the right direction, because the documentation looks Chinese to me. I just need a plain old html page.


    Christos


    • Edited by XristosK Thursday, March 06, 2014 3:56 PM
    Thursday, March 06, 2014 3:51 PM

Answers

  • Hi,

    [Update]

    Please try those solution. The first one used the xmlhttp to request the info and second one used the Ajax.

    Links:

    http://social.msdn.microsoft.com/Forums/en-US/53304ca2-6619-4df1-9b28-ee4dc7044c32/problem-migrating-to-the-new-windows-azure-bing-search-api?forum=DataMarket

    and http://social.msdn.microsoft.com/Forums/sqlserver/en-US/9f085915-81b6-488d-a348-1c3ca769d44f/migrating-to-windows-azure-bing-search-api-with-jquery-jsonp?forum=DataMarket

    Please try it.

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, March 07, 2014 6:13 AM
    Moderator
  • hi,

    You could try this code, I test it on my local.

    <head>
        <script type="text/javascript">
            function loadXMLDoc()
            {
                var xmlhttp;
                if (window.XMLHttpRequest)  
                {
                    // code for IE7+, Firefox, Chrome, Opera, Safari  
                    xmlhttp=new XMLHttpRequest();  
                }else  {
                    // code for IE6, IE5  
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
                }
                xmlhttp.onreadystatechange=function()  
                {  
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                    } else
                    {
                        document.getElementById("myDiv").innerHTML = xmlhttp.responseText+"state text:"+xmlhttp.statusText;
                    }
                }
                var requestStr = "https://api.datamarket.azure.com/Bing/SearchWeb/v1/Web?Query=%27willtest%27&$format=json";
                var requestStr2 = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web?Query=%27will%27&$top=10&$format=JSON";
                xmlhttp.open("Get", requestStr, true);
                xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(':***'));
                xmlhttp.send();
            }</script>
    </head>
    <body>
        <h2>Bing Test</h2><button type="button" onclick="loadXMLDoc()">Request data</button><div id="myDiv"></div>
    </body>

    Note:1. You need pay attention to "xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(CustomerID:Primary Account Key ));" or you could use "xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(:Primary Account Key ));" .

    2. If you test code on local, Please enable your IE broswer "access the data source across domain" setting. Like this:

    Please try it.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, March 12, 2014 6:21 AM
    Moderator

All replies

  • Hi,

    [Update]

    Please try those solution. The first one used the xmlhttp to request the info and second one used the Ajax.

    Links:

    http://social.msdn.microsoft.com/Forums/en-US/53304ca2-6619-4df1-9b28-ee4dc7044c32/problem-migrating-to-the-new-windows-azure-bing-search-api?forum=DataMarket

    and http://social.msdn.microsoft.com/Forums/sqlserver/en-US/9f085915-81b6-488d-a348-1c3ca769d44f/migrating-to-windows-azure-bing-search-api-with-jquery-jsonp?forum=DataMarket

    Please try it.

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, March 07, 2014 6:13 AM
    Moderator
  • Will,

    Thank you for your answer. I was able to make it run, but I get an error:

    if(typeof searchDone == 'function') searchDone({"SearchResponse":{"Version":"2.2","Query":

    {"SearchTerms":"Δοκίμια"},

    "Errors":[{"Code":1002,"Message":"Parameter has invalid value.",

    "Parameter":"SearchRequest.AppId",

    "Value":"d5dK\/XMLo0",

    "HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"}]}}

    /* pageview_candidate */);

    I get my AppID from page https://datamarket.azure.com/account in field: Primary Account Key.

    The actual http get is: (firefox console)

    http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sources=image&Appid=5dK/XMLo0&query=%CE%94%CE%BF%CE%BA%CE%AF%CE%BC%CE%B9%CE%B1

    and the relevant javascript line is:

    var AppId = "&Appid=5dK/XMLo0"; 

    I have truncated the AppId. I see that the AppId has a '/' inside. Strange.

    In my account/my data, I have both "Bing search API - Web results only" and "Bing Search API" and both are the free version.

    Any thoughts?


    Christos


    • Edited by XristosK Friday, March 07, 2014 1:49 PM
    Friday, March 07, 2014 10:52 AM
  • hi Christos,

    Sorry for my code, I posted my old version code for you in my first post. The service root URL and the method of Authorization is changed. I updated my post, You could try above two samples. If you occurred other questions, please let me know free.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, March 12, 2014 2:34 AM
    Moderator
  • hi,

    You could try this code, I test it on my local.

    <head>
        <script type="text/javascript">
            function loadXMLDoc()
            {
                var xmlhttp;
                if (window.XMLHttpRequest)  
                {
                    // code for IE7+, Firefox, Chrome, Opera, Safari  
                    xmlhttp=new XMLHttpRequest();  
                }else  {
                    // code for IE6, IE5  
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
                }
                xmlhttp.onreadystatechange=function()  
                {  
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                    } else
                    {
                        document.getElementById("myDiv").innerHTML = xmlhttp.responseText+"state text:"+xmlhttp.statusText;
                    }
                }
                var requestStr = "https://api.datamarket.azure.com/Bing/SearchWeb/v1/Web?Query=%27willtest%27&$format=json";
                var requestStr2 = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web?Query=%27will%27&$top=10&$format=JSON";
                xmlhttp.open("Get", requestStr, true);
                xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(':***'));
                xmlhttp.send();
            }</script>
    </head>
    <body>
        <h2>Bing Test</h2><button type="button" onclick="loadXMLDoc()">Request data</button><div id="myDiv"></div>
    </body>

    Note:1. You need pay attention to "xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(CustomerID:Primary Account Key ));" or you could use "xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa(:Primary Account Key ));" .

    2. If you test code on local, Please enable your IE broswer "access the data source across domain" setting. Like this:

    Please try it.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, March 12, 2014 6:21 AM
    Moderator
  • Thanks you share info

    please click:

    Wednesday, March 12, 2014 7:57 AM