I have a python function inside of node js server. I am trying to send the python result value from node js server to ajax.
const express = require('express');
const app = express();
const port = 8080;
var PythonShell = require('python-shell');
app.get('/', function(req, res) {
var options = {
mode: 'text',
pythonPath:'',
pythonOptions:['-u'],
scriptPath:'',
args: [req.query.country]
};
PythonShell.PythonShell.run('test.py', options, function(err, results) {
if(err) throw err;
console.log('results: ', results);
res.send(results.toString());
});
res.sendFile(__dirname + '/search.html');
});
$.ajax({
type: "GET",
url: 'http://localhost:8080/',
data: {country:country},
dataType:'text',
success: function(data) {
console.log('data: ', data);
}
});
I do not know which method I should use to send the result to ajax and I am not sure if the 'data' variable from ajax is proper way to use as the result which came from the server side.
Does anyone have any idea?