0

I'm using Node.js (on AWS Lambda for alexa skill) to request my web server for a JSON file. But my server responds with a 'Javascript' not supported error html.

This is my code:

function httpsGet(myData, callback) {
    // Update these options with the details of the web service you would like to call
    var options = {
        host: 'alexa0788.byethost24.com',
        port: 80,
        path: '/sample.php',
        method: 'GET',
    };

    var req = http.request(options, res => {
        res.setEncoding('utf8');
        var returnData = "";

        res.on('data', chunk => {
            returnData = returnData + chunk;
        });

        res.on('end', () => {

            console.log(returnData);
            var pop = JSON.parse(returnData).firstName + JSON.parse(returnData).lastName;

            callback(pop);  // this will execute whatever function the caller defined, with one argument

        });

    });
    req.end();
}

How can I make my server respond with the intended json and not force the client to support javascript? At the moment, I'm having a php file output the json. I tried calling a .json file too directly, instead of making a php file output json, but I see the same error.

halfpastfour.am
  • 5,764
  • 3
  • 44
  • 61
Krish
  • 917
  • 4
  • 10
  • 23
  • 1
    This should be changed on the server side of things. The problem is your alexa0788.byethost24.com and not your nodeJS application – itsundefined May 21 '17 at 20:43
  • Sure. Hence I've asked how can I make my server respond with json and not html.. I verified NodeJS with other servers, it works. – Krish May 21 '17 at 21:27
  • 1
    This is purely a PHP question. See http://stackoverflow.com/questions/4064444/returning-json-from-a-php-script for a start. – stdunbar May 22 '17 at 00:56

0 Answers0