Using the XML HTTP Request object
Using the XML HTTP Request object
Using XMLHTTP with GOOGLE's SOAP APIGoogle provides a SOAP interface to it's database. You need to register for a key that lets you make 1000 a day, to make a request. You then need to parse the returned XML.
search='Word'
xmlhttp.open('POST', 'http://api.google.com/search/beta2',true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText)
}
}
xmlhttp.setRequestHeader('Man', 'POST http://api.google.com/search/beta2 HTTP/1.1')
xmlhttp.setRequestHeader('MessageType', 'CALL')
xmlhttp.setRequestHeader('Content-Type', 'text/xml')
xmlhttp.send('<?xml version='1.0' encoding='UTF-8'?>'+'\n\n'+'<SOAP-ENV:Envelope'+
' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/''+
' xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance''+
' xmlns:xsd='http://www.w3.org/1999/XMLSchema'>'+
'<SOAP-ENV:Body><ns1:doGoogleSearch'+
' xmlns:ns1='urn:GoogleSearch''+
' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>'+
'<key xsi:type='xsd:string'>GOOGLEKEY</key> <q'+
' xsi:type='xsd:string'>'+search+'</q> <start'+
' xsi:type='xsd:int'>0</start> <maxResults'+
' xsi:type='xsd:int'>10</maxResults> <filter'+
' xsi:type='xsd:boolean'>true</filter> <restrict'+
' xsi:type='xsd:string'></restrict> <safeSearch'+
' xsi:type='xsd:boolean'>false</safeSearch> <lr'+
' xsi:type='xsd:string'></lr> <ie'+
' xsi:type='xsd:string'>latin1</ie> <oe'+
' xsi:type='xsd:string'>latin1</oe>'+
'</ns1:doGoogleSearch>'+
'</SOAP-ENV:Body></SOAP-ENV:Envelope>')
Google is using a SOAP interface, many people think SOAP has some serious issues worth considering. REST is probably a better model as it works with the current web framework, proxies, caches etc. So whilst we can use the XML HTTP Request object to talk soap, it's probably best not to unless you have no control over what's happening on the server end. (Thanks to Dan Schmierer for pointing out an error in my script.)
By default the object can only call back to the same server, in a reduced security environment (accessed from file:// say) IE can access any domain, Mozilla can also do that if you request and are granted the appropriate permissions see 'a google thread I can't get to offline!'
Nearby... Dynamically updating SVG. [1] Actually a lot of the 'AJAX' applications make little use of this object, using the older and often more flexible IFRAME remote scripting methods, but they could've been using this object, and AJAX should be thought of more as a concept of the kind of applications that can be created with the object.