I use this following from code inside ASPX page and it worked fine: put it all in the <HEAD> <head runat="server">
<title>Translate API Example</title> <div id="sourceText">How are you?</div> <div id="translation"></div> <script> function translateText(response) { document.getElementById("translation").innerHTML += "<br>" + response.data.translations[0].translatedText; } </script> <script> var newScript = document.createElement('script'); newScript.type = 'text/javascript'; var sourceText = escape(document.getElementById("sourceText").innerHTML); // WARNING: be aware that YOUR-API-KEY inside html is viewable by all your users. // Restrict your key to designated domains or use a proxy to hide your key // to avoid misuage by other party. // Works fine for french // var source = 'https://www.googleapis.com/language/translate/v2?key=YOURAPIKEY=en&target=fr&callback=translateText&q=' + sourceText; // for Arabic var source = 'https://www.googleapis.com/language/translate/v2?key= YOURAPIKEY&source=en&target=ar&callback=translateText&q=' + sourceText; newScript.src = source; // When we add this script to the head, the request is sent off. document.getElementsByTagName('head')[0].appendChild(newScript); </script> </head> On Thursday, February 2, 2012 8:32:59 AM UTC-6, Rik wrote: > This standard translate API V2 script (from http://code.google.com/apis) > isn't working. > Please could anybody body tell what's wrong, thanks a lot! > > <html> > <head> > <title>Translate API Example</title> > </head> > <body> > <div id="sourceText">Hello world, how are you?</div> > <div id="translation"></div> > <script> > function translateText(response) { > document.getElementById("translation").innerHTML += "<br>" + > response.data.translations[0].translatedText; > } > </script> > <script> > var newScript = document.createElement('script'); > newScript.type = 'text/javascript'; > var sourceText = > escape(document.getElementById("sourceText").innerHTML); > var source = 'https://www.googleapis.com/language/translate/v2? > key={API > <https://www.googleapis.com/language/translate/v2?key=%7BAPI>ID}&source=en&target=de&callback=translateText&q=' > + > sourceText; > newScript.src = source; > > document.getElementsByTagName('head')[0].appendChild(newScript); > </script> > </body> > </html> -- You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group. To post to this group, send email to google-ajax-search-api@googlegroups.com To unsubscribe from this group, send email to google-ajax-search-api+unsubscr...@googlegroups.com To view this message on the web, visit https://groups.google.com/d/msg/google-ajax-search-api/-/IM-SVaxbZPcJ For more options, visit this group at http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en