Hello, Prototype.js can not retrieve cross-domain ajax results because of security reasons. You may find few hacks(script tag hack) to do this client-side, try to googling 'cross-domain ajax request' but you may run into further issues. Your ajax code could target one of your server-side pages though.
Example for php, a page simply containing this: <? $your_url='http://ajax.googleapis.com/ajax/services/search/local?sll=28.2117,77.2629&mrt=localonly&q=DLF%20Building&v=1.0&rsz=large'; echo file_get_contents($your_url); ?> Note that you can pass url values with post or get to your server php page ($_GET or $_POST). ...and then in your previous code: new Ajax.Request('/page_on_same_domain.php', {method:'get'... Finally, I do not see any reason why you declare a second argument variable 'json' for your 'reportSuccess' function, as you declare it in its body. Just pass 'transport'. kv sumitarora a écrit : > I'm trying to call Google Search RESTful API using javascript > prototype library. > > Here is my code: > > new Ajax.Request('http://ajax.googleapis.com/ajax/services/ > search/local?sll=28.2117,77.2629&mrt=localonly&q=DLF > %20Building&v=1.0&rsz=large', > { > method:'get', > requestHeaders: {Accept: 'application/json'}, > onSuccess: reportSuccess, > onFailure: reportError > }); > > function reportError(request) > { > alert(request); > > } > function reportSuccess(transport, json) > { > var json = transport.responseText.evalJSON(true); > } > > But it returns nothing. > > Is there any way to call RESTful APIs using javascript, I don't want > to use Google's javascript controls. > > Thanks, > Sumit Arora > > > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.5.339 / Virus Database: 270.12.54/2158 - Release Date: 06/06/09 > 05:53:00 > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-AJAX-Search-API?hl=en -~----------~----~----~----~------~----~------~--~---
