Awesome, thanks for your help mate. As you may have already guessed, I 
haven't used JSONP before and don't know much about it. In the google 
translate docs, there's an example under REST using 
JavaScript<https://developers.google.com/translate/v2/getting_started#jsonp>, 
is this what jquery does under the hood when you specify dataType: 'jsonp' 
in an ajax call?

Anyway, back to the question at hand... I'm thinking that because I will 
potentially need to translate more than 5K characters at a time, I think 
I'll go about this a different way, use a GET and if the text is bigger 
than 2K, I'll do multiple requests to the translate service and join the 
results back up when they return. Thoughts on this approach?

On Sunday, April 7, 2013 2:16:30 PM UTC+12, jgeerdes [AJAX APIs "Guru"] 
wrote:
>
> That's okay. We used to support the Translate API over here and, in fact, 
> are still happy to do so as we can. At any rate, the problem is that JSONP 
> does not do POST requests. Instead of using a XMLHttpRequest, where you can 
> control headers and request method, it uses a script tag, where you can 
> only send information via GET. To do what you're wanting to do, you're 
> going to need to build a proxy on your own domain/server using PHP, Perl, 
> or some other server-side language. That way you can use an XMLHttpRequest 
> to send the data via POST to your server, which will relay the request to 
> Google's server and then return Google's response to your application.
>
> Don't forget to tell them over in the Translate API forum that we provided 
> the answer :D
>
> jg
>
> On Sat, Apr 6, 2013 at 6:55 PM, Andrew Beaven <[email protected]<javascript:>
> > wrote:
>
>> Sorry, wrong forum. Reposted in 
>> https://groups.google.com/forum/#!topic/google-translate-api/vFfr7lhWz1M
>>
>>
>> On Sunday, April 7, 2013 2:34:04 AM UTC+13, Andrew Beaven wrote:
>>>
>>> Hi there,
>>>
>>> I'm trying to call the Google Translate API using ajax like so:
>>>
>>> var Utils = {
>>>>     translate: function(message, callback) {
>>>>         $.ajax({
>>>>             type: 'POST',
>>>>             url: 
>>>> 'https://www.googleapis.com/**language/translate/v2<https://www.googleapis.com/language/translate/v2>
>>>> ',
>>>>             headers: { "X-HTTP-Method-Override": "GET" },
>>>>             dataType: 'jsonp',
>>>>             data: {
>>>>                 key: '<my key here>',
>>>>                 source: 'en',
>>>>                 target: 'ru',
>>>>                 q: message
>>>>             },
>>>>             success: callback
>>>>         });
>>>>     }
>>>> }
>>>
>>>
>>> I'm finding that when the message is too large, I get a 414 error, 
>>> indicating that the request URL is too large - it looks like the message 
>>> is concatenated onto the request URL. I'm confused by this because I had 
>>> thought that data sent in POST ajax requests were not sent via parameters 
>>> in the URL. The translate docs mention if you want to sent lots of data, to 
>>> do so via a POST, so I thought I'd be fine
>>>
>>> Is there anything I'm doing wrong here?
>>>
>>  -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Google AJAX APIs" group.
>> To post to this group, send email to
>> [email protected] <javascript:>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> To view this message on the web, visit
>> https://groups.google.com/d/msg/google-ajax-search-api/-/XfBD35OP1m4J
>>
>> For more options, visit this group at
>> http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google AJAX APIs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected]<javascript:>
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Jeremy R. Geerdes
> Generally Cool Guy
> Des Moines, IA
>
> If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan 
> Church!
> http://www.debraheightswesleyan.org
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
To view this message on the web, visit
https://groups.google.com/d/msg/google-ajax-search-api/-/h8tnFmhrqNYJ
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to