【发布时间】:2015-08-20 15:24:11
【问题描述】:
我试图将一些数据从我的 php 页面发布到我的 node.js 服务器。我想从中获得响应。
这是我从当前在 apache 服务器上执行的 php 页面发送的 ajax 代码
function encryptCode()
{
var value = document.getElementById("code").value;
$.ajax({
url: "http://localhost:3000/insertUser",
type: "POST",
data: JSON.stringify(value),
dataType: 'json',
async: false,
contentType: 'application/json; charset=utf-8',
success: function(data)
{
alert(data);
}
});
}
我只想通过此代码在我的 node.js 页面中接收它
var BaseController = require("./Base"),
View = require("../views/Base"),
model = new (require("../models/ContentModel"));
module.exports = BaseController.extend({
name: "insertUser",
content: null,
run: function(req, res, next) {
model.setDB(req.db);
var self = this;
console.log(data);
/*this.getContent(function() {
// var v = new View(res, 'place');
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(self.content));
});*/
// console.log("go to hell");
},
});
这是我的 express.js 的控制器,我已使用此代码从我的 app.js 页面重定向它
app.all('/insertUser', attachDB, function(req, res, next) {
insertUser.run( req, res, next);
});
有人可以在 console.log 中帮助我吗?我收到 {} .....
【问题讨论】:
-
php 代码行中变量“value”的值是什么 ::>>> var value = document.getElementById("code").value;
-
ok 你知道node js中的调试吗
-
@Hiren “代码”是我将从 HTML 页面获得的值
-
@Ahmer 不合格兄弟
-
假设您在文本框中输入了一些文本,如果不是 JSON 值,则不会在 node.js 中解析。所以你想在你的控制器中得到结果
标签: javascript php jquery ajax node.js