Sunday, May 9, 2010

Ajax-curl wrapper for google suggestion

When you search for something in google then google provides with the suggestion for the items related to that. It is very helpful sometimes.

This implementation does similar to this. For a given string it gets the list from the google search complete so that it can be used while searching in ones own application.

The implementation uses mootols for the UI interface.

Two variants of the implementations are :

1) Without #queries per item
2) With #queries per item
File structure :
|-- index.html [demo file ]
|-- js
| |-- Autocompleter.js
| |-- Autocompleter.Request.js
| |-- Observer.js
| |-- mootools-1.2-core-nc.js
|-- css
| |--Autocompleter.css
|-- php
|-- script.php

HTML:
|< type="text" name="q" id="suggestion">|

JavaScript:
Without number of queries :

document.addEvent('domready', function() {
var inputWord = $('suggestion');
new Autocompleter.Request.HTML(inputWord, 'php/script.php', {
'indicatorClass': 'autocompleter-loading'
});
});

With number of queries :

document.addEvent('domready', function() {
var inputWord2 = $('suggestion');
new Autocompleter.Request.HTML(inputWord2, 'php/script.php', {
'indicatorClass': 'autocompleter-loading',
// send additional POST data to get the #queries
'postData': {
'extended': '1'
},
// to remove span
'injectChoice': function(choice) {
var text = choice.getFirst();
var value = text.innerHTML;
choice.inputValue = value;
text.set('html', this.markQueryValue(value));
this.addChoiceEvents(choice);
}
});
});

PHP:
To set proxy :
change $useProxy = true
and enter the proxy details
$proxy = new Proxy("server", port, "username", "password" );

Link for the Demo

Download from here

2 comments:

Mayank Singhal said...

Infinite Craxxxx Code!

JS bhi google wali hai or your own?

kumar lav said...

JS are from the mootools library