weixin_33737134 2016-11-18 18:13 采纳率: 0%
浏览 115

Ajax请求失败

The Post requests stay pending. I wanted to log the JSON body of the incoming request. The request works when using Postman but the AJAX requests dont work

Node Code:

var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');

var hostname = 'localhost';
var port = 3000;

var app = express();

app.use(morgan('dev'));

var qRouter = express.Router();
qRouter.use(bodyParser.json());

qRouter.route('/')
.all(function(req,res,next) {
      res.header('Access-Control-Allow-Origin', "*")
      res.writeHead(200, { 'Content-Type': 'application/json' });
      next();
})
.post(function(req,res){
  console.log(req.body);
  res.end("lalal");
})
app.use('/play',qRouter);

app.listen(port, hostname, function(){
console.log(`Server running at http://${hostname}:${port}/`);
});

AJAX REQUEST

    var d = {
    "rating": 5,
    "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
        "author": "Paul McVites"
  }

  $.ajax({
      url: 'http://localhost:3000/play',
      type: 'POST',
      contentType: 'application/json',
      data: JSON.stringify(d)
  });
  • 写回答

1条回答 默认 最新

  • weixin_33708432 2016-11-18 19:15
    关注

    I think you are not handling your the response of your ajax call with jQuery. You are sending the data, but I don't see you receiving the server response. POSTMAN handles this automatically for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器