4

I'm using jQuery, jQuery-UI auto complete along with this link as 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 bug image: https://i.stack.imgur.com/NYMPG.jpg

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Shreyansh
  • 98
  • 8
  • 1
    Welcome to Stack Overflow. You really, *really* don't need to put "[possible duplicate]" in the question. If it is a duplicate, you already found the answer. Otherwise, it is OK. Good luck! – Kobi Sep 17 '13 at 13:17
  • Their server is not returning you JSONP. Your jQuery is expecting that, so it's not working. – gen_Eric Sep 17 '13 at 13:18
  • OKay @Kobi will keep that in mind for my next questions.. – Shreyansh Sep 18 '13 at 07:14
  • @RocketHazmat yeah i guess the server is just returning JSON & cross domain origin policy won't allow me to access json..So should i try yql to get data? – Shreyansh Sep 18 '13 at 07:16
  • @Shreyansh: You can use that, or your own server-side proxy. Not sure if it's against Google's TOS, though. You can also use YQL to get Yahoo's finance data instead. – gen_Eric Sep 18 '13 at 13:19

1 Answers1

2

The URL is not returning JSON-P. The error message is because JSON-P works by loading a remote JavaScript (and that isn't what the URL returns).

Since you aren't Google, you can't make that URL return JSON-P.

I'd suggest alternative approaches to getting the data, but Google don't provide an API for that data so you would be walking into Terms of Service violation territory.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • the stream of google finance I'm using it is still working,can't we term that as an undocumented api & use that for my project? – Shreyansh Sep 18 '13 at 07:20