0

I am trying to get the Json result from the yahoo finance search box and I need it as autocomplete format. I need it generate a div with the result. When I click on a element I need to send it to python script. Here what I done, but does not work, Any help?

$(function() {

  $("#find").autocomplete({
    source: function(request, response) {
      $.ajax({
        url: "https://query2.finance.yahoo.com/v1/finance/search?q=" + request.term,
        dataType: "json",
        data: {
          term: request.term
        },
        success: function(data) {
           console.log(data)
          var transformed = data.items.map(function(item) {
            return {
              exchange: item.quotes.exchange,
              shortname: item.quotes.shortname,
            };
          });
          response(transformed);
        }
      });
    }
  }).autocomplete("instance")._renderItem = function(ul, item) {
    return $("<li></li>")
      .data("item.autocomplete", item)
      .append("<a>" + item.exchange + "/><br />")
  };
});
DevLeo
  • 83
  • 1
  • 13
  • If you look at the response of the AJAX call in devtools ([demo here](https://jsfiddle.net/RoryMcCrossan/orsedmbg/)) you'll see this error: `Access to XMLHttpRequest at 'https://query2.finance.yahoo.com/v1/finance/search?q=tesla' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource`. This is because CORS headers are not included in the response. As such you will not be able to make AJAX requests to the Yahoo Finance API from client-side JS. See the duplicate I marked for more information about this – Rory McCrossan May 25 '21 at 09:48
  • can you indicate me a link, an code example? – DevLeo May 25 '21 at 10:50
  • Link is in the box above your question. There is no code example as what you're attempting to do isn't possible. – Rory McCrossan May 25 '21 at 10:51
  • I would suggest deleting this question and starting a new one about your specific axios/cheerio issue – Rory McCrossan May 25 '21 at 12:05

0 Answers0