Error matching Google Finance

I am using jQuery, jQuery-UI auto complete along with this link as a source

https://www.google.com/finance/match?matchtype=matchall&callback=callback&q=aa&_=1379423108762 

here is my code:

  $("#searchinput").autocomplete({ source: function (request, response) { var q=request.term; $.ajax({ type: "GET", // url: "http://d.yimg.com/autoc.finance.yahoo.com/autoc", for http use only url: "https://www.google.com/finance/match?matchtype=matchall", data: {q: q}, dataType: "jsonp", contentType: 'application/json; charset=utf-8', jsonp : "callback", jsonpCallback: "callback", }); // call back function callback = function (data) { var suggestions = []; //alert(JSON.stringify(data.matches)); $.each(data.matches, function(i, val) { suggestions.push("Name:"+ val.n+" #Symbol:"+val.t+" #Exchange:"+val.e); }); response(suggestions); } }, minLength: 1, select: function (event, ui) { $("#searchinput").val(ui.item.value.split("#")[0]); }, }); 

I get the following error

Uncaught SyntaxError: Unexpected token:

here you can see the error image: http://i.stack.imgur.com/NYMPG.jpg

+4
source share
1 answer

The URL does not return JSON-P. The error message is due to the fact that JSON-P works by loading remote JavaScript (and this is not what the URL returns).

Since you are not Google, you cannot force this URL to return JSON-P.

I suggest alternative approaches to receiving data , but Google does not provide an API for this data so that you can go to the territory of violation of the Terms of Service.

+2
source

Source: https://habr.com/ru/post/1502611/


All Articles