How to make a simple web page displaying Bing Translator API results?
-
30-10-2019 - |
Question
I want to use Bing Translator API to automatically translate some text in a page.
So, I'm using this code with my APP ID filled:
<script type="text/javascript">
var Translate={
baseUrl:"http://api.microsofttranslator.com/V2/Ajax.svc/",
appId:"MY_APP_ID_HERE",
translate:function(text,from,to,callback){
var s = document.createElement("script");
s.src =this.baseUrl+"/Translate";
s.src +="?oncomplete="+callback;
s.src +="&appId="+this.appId;
s.src +="&from" + from ;
s.src += "&to=" + to ;
s.src += "&text=" + text;
document.getElementsByTagName("head")[0].appendChild(s);
}
}
var mycallback=function(result){alert(result)};
Translate.translate("Hello World","en","es","mycallback");
</script>
It works fine, displaying the result in an alert box.
My question : how to display the result on the page instead of in alert box ? Kind of document.write, I guess...
Thanks for your help,
E.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow