XMLHttpRequest error with Google translate (no header "Access-Control-Allow-Origin")

I get this error when trying to access a page using Google Translate:

XMLHttpRequest cannot load http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit . There is no "Access-Control-Allow-Origin" header in the requested resource. Origin http://localhost:8080'therefore access is not allowed.

I read a few posts about this problem here on SO, but I did not find a way to work with how we initialize the Google Translate gadget.

Suggested solutions include setting dataTypein jsonpand adding Access-Control-Allow-Origin: *to the header XMLHttpRequest. However, I am not making an AJAX call, as in other posts, only to initialize the Google Translate element using a script provided by Google:

<script type="text/javascript">
          function googleTranslateElementInit() {
                new google.translate.TranslateElement({pageLanguage: 'en',
                    layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
                    includedLanguages: 'fr,en'
                }, 'hiddenGoogleTranslate');
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

How can I define dataTypeor add something to the header with this script initialization? I am new to Javascript, so I have to miss something.

Thank!

+4
source share
1 answer

curl file_get_content() (webproxy) . URL- ajax. " " *, ( js). URL- .

0

All Articles