1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Jquery bug ? - getjson

Discussion in 'HTML & JavaScript' started by hip_hop_x, Nov 29, 2012.

  1. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Hey there so i got into abit of trouble

    The problem i am facing is that it never get's to the function(data,status)... and bugzilla reports that the call to that page is being made, also that response status is 200, and that there is a response.
    So why $.getJSON doesn't recognize it (also did try with $.ajax, same crap), i mean why it doesn't go to the function (data,status) when it is supposed to get there?

    PHP:
    function suggest(kw){
    console.log("Logging!");
    $.
    getJSON('http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&callback=?&q='+kw,
     function(
    data,status){
      $.
    each(data, function(i,item){alert(item.x);});
    });
    }
    If anyone has clue/fix let me know, thank you!
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    It 's a cross-domain request, it will never receive the response ;)

    In short, you can't make it work without server side code to fetch the result for you.
     
  3. alexglo

    alexglo Junior Member

    Joined:
    Aug 12, 2011
    Messages:
    166
    Likes Received:
    145
    Location:
    UK
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143


    What 's the chances of him being the owner of suggestqueries.google.com ? :D:D
     
  5. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    it's jsonp, so i can request thou any cross domain wich has a callback, and from bugzilla i see that i get a response, just that $.getJSON or $.ajax (type:jsonp) doesn't recognize the function (data) nor the success: function(data)...

    Any suggestions?


    Basicly cross domain isn't the case here, because i get the data, just that the js doesn't know where to parse it.
     
    Last edited: Nov 29, 2012
  6. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    nah, your url gives you pure json back
    to make it work you have to change the the client to youtube (chrome works also):
    Code:
    function suggest(kw){
        console.log("Logging!");
        $.getJSON('http://suggestqueries.google.com/complete/search?[color=red]client=youtube[/color]&hl=en-US&callback=?&q='+kw,
            function(data,status){
                console.log(data);
                $.each(data[1], function(i,item){alert(item[0]);});
        });
    }
    
     
    • Thanks Thanks x 2
  7. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    oh, thanks mate, you saved me from allot of trouble. The main problem why i choose to do this by client side is that it's saving time and it's not using server ip all the time to querry google suggestions.