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

435
Visualizações
How to send data from server side(node js) to client side(pug)?

I am trying to use ajax to send data from client-side to server-side without refreshing the page.

I am using this ajax code inside my pug file -

script.
        $(function() {
            $('#form1').submit(function(event) {
                event.preventDefault();
                var form = $(this);
                $.ajax({
                    type: form.attr('method'),
                    url: form.attr('action'),
                    data: {form.serialize()}
                });
            });
        });

I am using the same URL and the method(which is POST).

Router file:-

const express = require("express");

const main_controller = require("../../controllers/main-controller");

const router = express.Router();

router.post('/form', main_controller.Send);

module.exports = router;

Controller file:-

const data_model = require('../../models/data-model');

exports.Send = (req, res, next) => {
    data_model.find((err, data) => {
        res.render("./customer/form1", {
            pageTitle: "Form1",
            data: data
        });
    });
};

I want to filter the data I am sending above. In the form, I have dropdown boxes in which I'm displaying the data, when the user selects something, I am sending the option he chose to the server. In the server, I am filtering data based on the option that was selected. I want to send the filtered data back to the client-side, but I am not able to.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In jQuery, you can use the success callback or the .done Promise Resolution for accessing data sent back by the server for further processing. Please have [a look here at the documentation][1] for further examples on how to do this.

[1]: https://api.jquery.com/jquery.post/#:~:text=%24.post(%20%22test.php%22%2C%20%7B%20name%3A%20%22John%22%2C%20time%3A%20%222pm%22%20%7D),%7D)%3B

about 4 years ago · Juan Pablo Isaza Relatório
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