curl - google translate api trouble -


I am trying to put the Google translation API to work in my webapp. I am using some Ajax to load into a div, but when I take it on my laptop, I get an error about 50% of the time that it says that there is no index data from the JSN reaction . I think this is because the API has not responded so far, so I'm hoping that I keep a loop here to wait for the code, but I'm not sure where is the PHP page here that XML response Generates

  & lt ;? Php header ('content-type: text / xml'); $ Cc_nlc = 'good'; If (isset ($ _ POST ['cc_nlc'])) {$ cc_nlc = $ _POST ['cc_nlc']; If (empty ($ cc_nlc)) {$ cc_nlc = 'not very good'; }} Echo & lt ;? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"? & Gt; '; Echo '& lt; Feedback & gt; '; Echo & lt; Translation & gt; '; $ Apikey = 'my key'; $ Url = 'https://www.googleapis.com/language/translate/v2?key=' $ apk '& Amp; Q = 'crude node ($ cc_nlc)' & Amp; Source = hi & amp; Target = ar '; $ Handle = curl_init ($ url); Curl_setopt ($ handle, CURLOPT_RETURNTRANSFER, true); $ Response = curl_xac ($ handle); $ ResponseDecoded = json_decode ($ response, true); Curl_close ($ handle); // print_r ($ responseDecoded); $ Translation = $ responseDecoded ['data'] ['translation'] [0] ['translated text']; Transcript $ translation; Echo & lt; / Translation & gt; '; Echo '& lt; / Response & gt; '; ? & Gt;  


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -