javascript - 将python结果从节点js发送到ajax
问题描述
我在节点 js 服务器中有一个 python 函数。我正在尝试将 python 结果值从节点 js 服务器发送到 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);
}
});
我不知道应该使用哪种方法将结果发送到 ajax,并且我不确定来自 ajax 的“数据”变量是否适合用作来自服务器端的结果。
有人有什么主意吗?
解决方案
推荐阅读
- c# - 如何在构造函数之外实例化?
- python - Python:在文件范围内循环
- java - 如何修复 HTTP 状态 500 - 内部服务器错误 | 小服务程序错误
- java - Android:主要项目所依赖的库中的 NFC 意图
- react-native - 反应原生 flatlist androidTV 焦点问题
- apache-spark - Spark 默认类
- python - 使用具有不同范围图的 mark_inset
- mongodb - 从 Python Eve 连接到访问受控的 MongoDB 副本集
- c++ - 类模板特化从不同的基类继承是否合法?
- macos - 使用 Lua 编程 Mac 键