0

I am trying to fetch image from Bing.com with jquery ajax to set my website background .

I see a post and try with JSON format with bellow code.

<head>
     <script src="https://code.jquery.com/jquery-3.4.1.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 ) {
  console.log(data)

  });

})();

In browser network tab its shows the response enter image description here

But ,in console I got error . enter image description here

Please tell me what is going wrong a and how to fix.

kuntal
  • 1,591
  • 2
  • 16
  • 36
  • You're hitting the CORS restrictions that browsers and servers enforce. Bing apparently does not allow ajax requests from off site clients to fetch their resources directly. – Taplar Nov 11 '19 at 18:21
  • Thanks for your comment,but I have an question in my mind,can you please help me with that ?I see a link in codeproject https://www.codeproject.com/Articles/1119706/Get-Bing-Image-of-the-Day-using-Csharp.My question is then why its working with c# asp.net? – kuntal Nov 12 '19 at 13:07

0 Answers0