Google's translation API can be divided into free translation and literal translation. Google's translation API can easily provide translation functions for websites.
First, you need to look at the developer guide page to load Google's JsCode
<SCRIPT type = "text/JavaScript" src = "http://www.google.com/jsapi"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Google. Load ("language", "1 ");
</SCRIPT>
Then, Google. Language. Translate can be used to complete the translation. Here is an example document. For API instructions, see here.
You can use the developer guide page to easily obtain data, but the data is one-time. Fortunately, Google also provides other methods to return data, such as JSON.
Google translation API must use the get method to obtain data. The returned data format is JSON and the structure is as follows:
{
"Responsedata ":{
"Translatedtext": The-translated-text,
"Detectedsourcelanguage "? : The-source-language
},
"Responsedetails": NULL | string-on-error,
& Quot; responsestatus & quot;: 200 | error-code
}
The project uses the getjson method of jquery to obtain data and use it multiple times on the page, which is very flexible.
During this period, an error occurs, indicating that the corss domain requests data across domain names. Shown as: access to restricted URI denied "Code:" 1012 jquery
You can look at others' opinions, but I suggest you look at jquery's getjson method or look down.
Because of the security considerations of Web Services, cross-domain request is forbidden, a new josn concept jsonp was proposed to solve this problem, fortunately, Google, Flickr, and other data providers support jsonp.
Here are some documents to help you solve this problem.
Note that the transmitted parameters must be encoded; otherwise, 400 is returned.