none
Origin is not allowed when trying to make jQuery ajax request to Bing Search API

    Question

  • I have had this exact code working a week ago and suddenly it stopped working. I don't think anything has changed in bing's api, I have checked my account and still have plenty of searches left. I even mimic this exact request in fiddler and it works. Here is my code:

    function queryBing(query, start, callback) {
                var requestStr = "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Image?Query=%27" + query + "%27&$top=50&$format=json&ImageFilters=%27Size%3aMedium%27&Adult=%27Moderate%27";
                console.log(requestStr);
                console.log(accountKeyEncoded);
                jQuery.support.cors = true;
                $.ajax({
                    url: requestStr,
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader('Authorization', 'Basic ' + accountKeyEncoded);
                    },
                    context: this,
                    dataType: "json",
                    type: 'GET',
                    error: function(e){
                        e.Message;
                    },
                    success: callback
                });
            }

    And its returning the following error:

    OPTIONS https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Image?Query=%27te…$top=50&$format=json&ImageFilters=%27Size%3aMedium%27&Adult=%27Moderate%27 Origin http://localhost:81 is not allowed by Access-Control-Allow-Origin. jquery.js:8706

    XMLHttpRequest cannot load https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Image?Query=%27te…$top=50&$format=json&ImageFilters=%27Size%3aMedium%27&Adult=%27Moderate%27. Origin http://localhost:81 is not allowed by Access-Control-Allow-Origin. 

    I have been able to query from my local computer and my website a week ago. I tried looking inside my account settings and i cant find anywhere in Bing where I would ADD my domain.


    • Edited by anthonypliu Wednesday, November 06, 2013 7:37 PM
    Wednesday, November 06, 2013 7:36 PM

Answers