Post by Sential on Sept 12, 2015 3:03:47 GMT 10
Where are Google suggestions? I want to add Google suggestions to my autocomplete system in WebExpress. Can you give me a link?
|
|
Post by Nathan Lecompte on Sept 28, 2015 21:03:34 GMT 10
Hey Sential, Sorry for the late response; this gives back a jsonp response: clients1.google.com/complete/searchIt's the same for the Google Clone's Suggest.js script. Like this here: $.fn.googleSuggest = function(opts){ opts = $.extend({service: 'web', secure: false}, opts);
var services = { youtube: { client: 'youtube', ds: 'yt' }, books: { client: 'books', ds: 'bo' }, products: { client: 'products-cc', ds: 'sh' }, news: { client: 'news-cc', ds: 'n' }, images: { client: 'img', ds: 'i' }, web: { client: 'psy', ds: '' }, recipes: { client: 'psy', ds: 'r' } }, service = services[opts.service];
opts.source = function(request, response){ $.ajax({ url: 'https://clients1.google.com/complete/search', dataType: 'jsonp', data: { q: request.term, nolabels: 't', client: service.client, ds: service.ds }, success: function(data) { uquery = data[1][0].toString(); tquery = uquery.split(",0"); window.squery = tquery[0]; if(window.squery!="undefined" && window.squery!=query){ window.squery = window.squery.replace('<b>',''); window.squery = window.squery.replace('</b>',''); window.squery = window.squery.replace('\u003cb\u003e',''); set_query(window.squery); if(window.squery.indexOf($("#q").val())>-1){ $("#sug").val(query); }else{ $("#sug").val(""); } } else if(window.squery=="undefined"){ set_query(""); } response($.map(data[1], function(item){ return { value: $("<span>").html(item[0]).text() }; }).slice(0, 5)); } }); };
Hope this helps!
|
|