Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Sending python result from node js to ajax

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda