1

I have java script . now i want to pass the variable and get output of this script. I little confuse .how to do this?? My script is like this

function doGet(e) {

  var sourceText = 'hiren'
  if (e.parameter.q){
    sourceText = e.parameter.q;
  }

  var sourceLang = 'auto';
  if (e.parameter.source){
    sourceLang = e.parameter.source;
  }

  var targetLang = 'ja';
  if (e.parameter.target){
    targetLang = e.parameter.target;
  }

  /* Option 1 */

  var translatedText = LanguageApp.translate(sourceText, sourceLang, targetLang)

  /* Option 2 */  

  var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" 
            + sourceLang + "&tl=" + targetLang + "&dt=t&q=" + encodeURI(sourceText);

  var result = JSON.parse(UrlFetchApp.fetch(url).getContentText());

  translatedText = result[0][0][0];

  var json = {
    'sourceText' : sourceText,
    'translatedText' : translatedText
  };

  // set JSONP callback
  var callback = 'callback';
  if(e.parameter.callback){
    callback = e.parameter.callback
  }

  // return JSONP
  return ContentService
           .createTextOutput(callback + '(' + JSON.stringify(json) + ')')
           .setMimeType(ContentService.MimeType.JAVASCRIPT);
}

for out put i try this php script but it does not work. it is like this

<?php $myphotoid = "<script language='javascript'>translatedText</script>";
echo $myphotoid;
 ?>

but it does not give the output of the script. all i want is to input here var sourceText = 'hiren' and get the output. i do not understand how to do this??

7

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.