4
I created the route below to accept POST requests, but calls via AJAX to this route are always returning error 404: Not Found.
/* Arquivo: integracoes.js */
var express = require('express');
var router = express.Router();
// Esta rota funciona e não dá erro: http://localhost:3001/integracoes/consultas
router.get('/consultas', function(req, res, next) {
res.render('consultas');
});
// 404: Not Found quando chamado pela requisição Ajax descrita mais à frente nessa pergunta.
router.post('/consulta/statuspedido', function(req, res) {
var statusDoPedido = 10;
res.send(JSON.stringify({statuspedido: statuspedido}));
});
module.exports = router;
In app.js I use this definition of routes as follows:
var integracoes = require('./routes/integracoes');
app.use('/integracoes', integracoes);
On the HTML page I am using the following called Ajax:
$.ajax({
url: '/consulta/statuspedido',
contentType: 'application/json',
type: 'POST',
success: function(data) {
debugger;
textAreaDeResposta.val(imprimaCamposDoObjeto(data));
},
error: function(){
textAreaDeResposta.val('Ocorreu um erro ao tentar consultar o status do pedido.');
}
});
In the Browser the answer I get is the following:
http://localhost:3001/query/status 404 (Not Found)
The site is configured to run on port 3001, and all other routes of the site (GET) are working. The only one that doesn’t work is the one I’m trying to access via AJAX.
Why URL not found?