我试图将(jQuery ajax)JSON对象数组发布到我的服务器(使用BodyParser中间件的Express Routing节点)。这适用于小JSON对象,但是当我尝试发布包含坐标对数组的JSON对象时,帖子失败。它甚至没有击中我的路线?
以下是我的代码的简单版本。
我想发布的JSON对象(这是一个数组)
var featureArray = [ 0:对象 geometry:Object 坐标:数组[1] 0:数组[368] [0 ... 99] [100 ... 199] [200 ... 299] [300 ... 367] ... ]
客户端Ajax
insert: function(featureArray,callback){
$.ajax({
type:'POST',
url: '/insert',
dataType: '',
data: {docs:featureArray},
cache: false,
success: function(data,textStatus,XMLHttpRequest) {
callback()
},
error: function (responseData, textStatus, errorThrown) {
console.log("Error Pulling Data")
}
});
},
快速路线testRoute.js
var express = require('express')
var router = express.Router()
router.post('/insert',function(req, res) {
q = req.body
console.log(q.docs)
})
module.exports = router
Express App index.js
var express = require('express');
var testRoutes = require('./routes/testRoute');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json({limit: '500mb'}));
app.use(bodyParser.urlencoded({limit: '500mb', extended: true}));
app.use('/', testRoutes);
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 3000;
app.set('port', port);
app.set('ipaddress', ipaddress);