开发者

Google autocomplete with jquery

i know, there is a gcomplete plugin, but i try to build my own. My problem is that i dont get an answer.

JS

$.get("http://www.google.com/complete/search?qu=chicken", function(data)
 {

     $('body').append("Data Loaded: " + data);

    $.each(data, function(i)
    {              开发者_如何学JAVA  
       $('body').append('- '+data[i]+' <br />');

    });

 });

Hope somebody can help me.

Example http://www.jsfiddle.net/V9Euk/652/

Thanks in advance!

Peter


You need to make your datatype JSONP because you're getting the data from a different domain, for this you'll need to use the AJAX function rather that get

$(function() {

    $.ajax({
        url:"http://www.google.com/complete/search?qu=chicken",
        success:function(data){
            $('body').append("Data Loaded: " + data);
        },
        dataType:'jsonp',
        error:function(){
            alert('error');
        }
    });
});

http://www.jsfiddle.net/V9Euk/653/


Unless your Javascript isn't hosted on the same domain as you are trying to post to, you won't get an answer. In this case, your code is on www.jsfiddle.net, but you are trying to fetch data from www.google.com.

This can easily be worked around by using JSONP instead of JSON. See the dataType parameter of the jQuery.ajax function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜