0

I am trying to get a string from my APEX site to the following node js webserver:

tts = require('node-tts-api');
express = require('express');

var app = express();

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});

app.get('/hello/:text', function(req, res){
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    var text = req.param('text');

    tts.getSpeech(text, function(error, link) {
        res.write(link);
        res.end();
  });
});

var server = app.listen(3000, function(){
      console.log('Listening on port 3000');
});

In APEX I execute the following dynamic javascript action:

var url = 'http://127.0.0.1:3000/hello/' + $('#P4_TEXT').val();
$.get( url, function( data ) {
  var url = data;
   console.log('get start');
   console.log(url);
  var player = document.createElement('player');
  player.setAttribute('src', url);
  player.setAttribute('type', 'audio/mp3');
  document.body.appendChild(player);
  player.play();
});

The console does not show any of the log entries I added for debugging. When I start the dynamic action, nothing happens. When I enter the URL manually, the browser loads forever but does not get any data back. Are there any mistakes or did I understand something wrong?

Steven
  • 135
  • 2
  • 11

2 Answers2

1

On client side you can use form with submit input/button. On server side I can suggest you use Express and body parser. Example you can find there: How to retrieve POST query parameters?

Community
  • 1
  • 1
magmel
  • 590
  • 4
  • 14
1

Just changed the dynamic action to the following code and everything works fine.

   var url = 'http://apex.mt-ag.com:1337/tts/' + $( P4_X ) .val();
    $.get( url, function( data ) {
      var url = data;
       console.log('get start');
       console.log(url);
    var snd = new Audio(url);
    snd.play();
     });
Steven
  • 135
  • 2
  • 11