Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

express的请求问题

$
0
0

最近在学校做一个项目涉及到web服务器,开始学了node.js,但是在用ajax向服务器提交请求时出现了问题,无法接收到get请求(post也接收不到)看了好多文档都没解决只能来求助了,app.js和路由还有ajax的源码如下: ajax: function sensor(obj) { var j_data1 = [ [] ]; $.ajax({ type: “GET”, url: “/chart”, data: { node_name: $(obj).parent(‘ul’).parent(‘li’).children(‘a’).children(‘span’).innerText, sensor_name: $(obj).innerText }, datatype: “json”, success: function(data) { if(data.success) { j_data1[0] = eval(obj).sensor; j_data1[1] = eval(obj).sensor_up; j_data1[2] = eval(obj).sensor_down; return j_data1; } else { alert(“出现错误”) } } }) 路由因为接收不到请求只是单纯的写了 module.exports = function(app) { … app.get(’/chart’,function (req, res) { …处理}); } app.js var express = require(‘express’); var path = require(‘path’); var favicon = require(‘serve-favicon’); var logger = require(‘morgan’); var cookieParser = require(‘cookie-parser’); var bodyParser = require(‘body-parser’); var session=require(‘express-session’); var cassandracqlstore=require(‘connect-cassandra-cql’)(session); var cassandra=require(‘cassandra-driver’); var flash=require(‘connect-flash’); var routes = require(’./routes/index’); var app = express();

var client =new cassandra.Client({contactPoints:[‘localhost’],keyspace:‘iotserver’}); var config={client:client};

app.set(‘port’, process.env.PORT || 3000); app.set(‘views’, path.join(__dirname, ‘views’)); app.use(flash()); //app.engine(“html”,require(‘ejs’).__express); app.set(‘view engine’, ‘ejs’); //app.set(‘view engine’, ‘html’); app.use(favicon(__dirname + ‘/public/favicon.ico’)); app.use(logger(‘dev’)); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(cookieParser()); app.use(express.static(path.join(__dirname, ‘public’))); app.use(session({ secret:‘keyboard-cat’, store:new cassandracqlstore(config), resave:true, saveUnintialized:true}));

routes(app); app.listen(app.get(‘port’), function() { console.log('Express server listening on port ’ + app.get(‘port’)); }); 先谢谢了


Viewing all articles
Browse latest Browse all 14821

Trending Articles