javascript - Google auto complete on textbox? -


i want show google search auto completes in textbox. after searching google found "http://google.com/complete/search?output=toolbar&q=test" link return xml data contains ten google search suggets. jquery code showing xml values :

$(window).ready(function(){     $( "#textbox" ).keypress = showsuggest(); }); function showsuggest() {     $.ajax({         type: "get",         url: "http://google.com/complete/search?output=toolbar&q=" + $("#textbox").val(),         datatype: "xml",         var data = [];         success: function(xml) {             $(xml).find('completesuggestion').each(function(){             data.push($(this).find('suggestion')[0].attr('data'));         });         }     });     $( "#textbox" ).autocomplete({         source: data     }); } 

jquery-1.9.1.js , jquery-ui-1.10.3 imported code not working. sorry bad english. thanks.

update

thanks everyone. edit code , remove xml reading part , replace

url: "http://google.com/complete/search?output=toolbar&q=" + $("#textbox").val() $("#textbox").autocomplete({    source: data }); 

with :

$( "#textbox" ).autocomplete({ source: "http://suggestqueries.google.com/complete/search?client=firefox&q=" + $( "#textbox" ).val() }); 

now on typing text show progress image left side of textbox , still not showing suggets. please help.

new update

i write new code firefox domparser still not working.

    $("#textbox").keypress(function() {     var data = [];     var parser = new domparser();     var xml = parser.parsefromstring("http://google.com/complete/search?output=toolbar&q=" + $("#new-tag-post_tag").val(), "application/xml");     xml.domain = "google.com";     suggests = getelementsbytagname("completesuggestion");     (var = 0; < suggests.length; i++) {         data.push(suggests[i]);     }     $( "#textbox" ).autocomplete({         source: data     }); } 

$(document).ready(function(){     $( "#textbox" ).keypress(showsuggest); });                  function showsuggest() {      // declare variable here, not inside $.ajax code     var data = [];      $.ajax({         type: "get",         url: "http://google.com/complete/search?output=toolbar&q=" + $("#textbox").val(),         datatype: "xml",                     success: function (xml) {             $(xml).find('completesuggestion').each(function () {                 data.push($(this).find('suggestion')[0].attr('data'));                                  $("#textbox").autocomplete({                    source: data                  });             });           }     }); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -