<div id="gt-res-content" class="almost_half_cell"> <div dir="ltr">Hi all,</div> <div dir="ltr">I entered theMicrosoft Translatorin my
aspx page. someonecan tell me
how do Iintercept theupdatepage afterthe translation
has beendone?BecauseI dounleash
a functionat the end oftranslation... thanks</div> <div dir="ltr"></div> <div dir="ltr">bye </div> </div>
Hi, you can call your JavaScript function within Microsoft Translator Translate method, please refer to the following site: http://forums.asp.net/t/1762797.aspx
and call your function:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var languageFrom = "en";
var languageTo = "es";
var text = "translate this.";
function translate() {
window.mycallback = function (response) {
//you javascript function here, for example
//alert("hello");
alert(response); }
var s = document.createElement("script");
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=mycallback&appId=myAppId&from=" + languageFrom + "&to=" + languageTo + "&text=" + text;
document.getElementsByTagName("head")[0].appendChild(s);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" onclick="translate();" />
</div>
</form>
</body>
</html>
I have a button that shows me the translator (http://www.microsofttranslator.com/widget/)
then I click the play button on the translator, and he sends the ajax request to the server.
I want to intercept the response that comes on the client ...
Like you said I understood, but the translate() function how do I call? Clicking the play button does not go ..
dupin
Member
219 Points
203 Posts
refresh ajax
Jan 26, 2012 08:55 AM|LINK
someone can tell me how do I intercept the update page after the translation has been done? Because I do unleash a function at the end of translation... thanks</div> <div dir="ltr"></div> <div dir="ltr">bye
</div> </div>
Allen Li - M...
Star
10411 Points
1196 Posts
Re: refresh ajax
Jan 30, 2012 07:51 AM|LINK
Hi, you can call your JavaScript function within Microsoft Translator Translate method, please refer to the following site:
http://forums.asp.net/t/1762797.aspx
and call your function:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var languageFrom = "en"; var languageTo = "es"; var text = "translate this."; function translate() { window.mycallback = function (response) { //you javascript function here, for example //alert("hello"); alert(response); } var s = document.createElement("script"); s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=mycallback&appId=myAppId&from=" + languageFrom + "&to=" + languageTo + "&text=" + text; document.getElementsByTagName("head")[0].appendChild(s); } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="Button1" type="button" value="button" onclick="translate();" /> </div> </form> </body> </html>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
dupin
Member
219 Points
203 Posts
Re: refresh ajax
Jan 30, 2012 08:19 AM|LINK
Hi,
I can not...
I have a button that shows me the translator (http://www.microsofttranslator.com/widget/)
then I click the play button on the translator, and he sends the ajax request to the server.
I want to intercept the response that comes on the client ...
Like you said I understood, but the translate() function how do I call? Clicking the play button does not go ..
thank you very much
Allen Li - M...
Star
10411 Points
1196 Posts
Re: refresh ajax
Feb 01, 2012 08:58 AM|LINK
Hi, with Microsoft Translator Widget, you can try the following method:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function loadMSTranslator() { var s = document.createElement("script"); s.src = ((location && location.href && location.href.indexOf('https') == 0) ? "https://ssl.microsofttranslator.com" : "http://www.microsofttranslator.com") + "/ajax/v2/widget.aspx?mode=notify&from=en&layout=ts"; document.getElementsByTagName("head")[0].appendChild(s); } function polldom() { var d = document.getElementById('MSTWGoButton'); if (d) { d.addEventListener('click', function () { //your code here, for example: //alert('clicked'); }); } else { setTimeout(polldom, 1000); } } loadMSTranslator(); polldom(); </script> </head> <body> <form id="form1" runat="server"> <div> check this page </div> </form> </body> </html>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
dupin
Member
219 Points
203 Posts
Re: refresh ajax
Feb 01, 2012 09:18 AM|LINK
Hi,
thanks .. Works fine in firefox.. just that I wanted!
But in IE shows this:
Error: Object does not support this property or method 'addEventListener'
why? you have any ideas?
thanks
Allen Li - M...
Star
10411 Points
1196 Posts
Re: refresh ajax
Feb 02, 2012 12:27 AM|LINK
Hi, for the IE versions lower than IE9, you can add “attachEvent” method. You can refer to the following codes and check the result again.
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript"> function loadMSTranslator() { var s = document.createElement("script"); s.src = ((location && location.href && location.href.indexOf('https') == 0) ? "https://ssl.microsofttranslator.com" : "http://www.microsofttranslator.com") + "/ajax/v2/widget.aspx?mode=notify&from=en&layout=ts"; document.getElementsByTagName("head")[0].appendChild(s); } function polldom() { var d = document.getElementById('MSTWGoButton'); if (d) { if (d.addEventListener) { d.addEventListener('click', function () { //your code here, for example: alert('clicked'); }); } else if (d.attachEvent) { d.attachEvent('onclick', function () { //your code here, for example: alert('clicked'); }); } } else { setTimeout(polldom, 1000); } } loadMSTranslator(); polldom(); </script> </head> <body> <form id="form1" runat="server"> <div> check this page </div> </form> </body> </html>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
dupin
Member
219 Points
203 Posts
Re: refresh ajax
Feb 02, 2012 08:03 AM|LINK
Hi Allen...
perfect .. very professional .. thank you very much