1

I have made an Ajax call to Bing to get its daily image, however i get an error in the console:

enter image description here

this is the full code its on a localhost using wamp

index.php

<head>

    <script src="jquery.min.js"></script>
</head>
<body>
    <div id="output"></div>
</body>

<script type="text/javascript">

    $.ajax({
        url : "http://bing.com/HPImageArchive.aspx?format=js&idx=0&n=1",
        dataType:"jsonp",
    });

    function mycallback(data)
    {
        $('#output').html(data.images[0].url);
    }

</script>
levi lucas
  • 99
  • 1
  • 2
  • 12

2 Answers2

0

I think you should study the documention for jquery ajax call.

<head>
    <script src="jquery.min.js"></script>
</head>
<body>
    <div id="output"></div>
</body>

<script type="text/javascript">

(function() {
  var bingImagesUrl = "http://bing.com/HPImageArchive.aspx";
  $.getJSON( bingImagesUrl, {
    idx:0,
    n:1,
    format: "js"
  }).done(function( data ) {
        $('#output').html(data.images[0].url);
  });

})();

</script>
Below the Radar
  • 7,321
  • 11
  • 63
  • 142
  • I have given the above ago, however still have the same error confusing me as i have tried a number of ajax calls i tried jsonp, but that is refering to header access control – levi lucas Oct 08 '15 at 08:28
0

@Below_the_Radar: your answer does not really help as OP is likely getting the same error even if he makes the Ajax call correctly.

According to Is there a way to get Bing's photo of the day?, it seems that Bing.com only supports XML, JSON, and RSS. I guess OP want to make the call with dataType: "jsonp" probably because he would like to bypass the browsers same-origin policy.

This can be solved client-side in browser by using a Chrome extension, but I guess that is not OP's use case. I bet OP is trying to get a picture from Bing's archive and thus use it in his own website. If that is the case, it has no solution as we need to have "Access-Control-Allow-Origin": "*" in the response's headers returned by Bing, which we do not have control.

I suggest considering an alternative. Try this: https://source.unsplash.com/

Roman Wang
  • 11
  • 3