大家好我有这样的代码
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;
req.body = _.omit(req.body, '__proto__');
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(req.body));
/*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");
},
但它正在向我发送此格式的回复
{ “{\” 代码\ “:\” OU4 \ n \u0013|é\ “\ ”年龄\“:25} ”:“”, “的原”:{} }
我只想删除“ proto ”:{}或者特别是sal我希望得到像这样的输出
"{\"code\":\"Øù4\\n\\u0013¦é\",\"Age\":25}"
请你们查看我犯错误或错误的地方
好吧,我通过这个过程将ajax请求发送给控制器
function encryptCode()
{
var value = document.getElementById("code").value;
var key = "secretKeyToProvide"; /*--Provide Your secret key here--*/
var codeValue = rc4(key, value);
var arr = {code:codeValue, Age:25};
var request =
$.ajax({
url: "http://localhost:3000/insertUser",
type: "POST",
data: JSON.stringify(arr),
dataType: 'json',
async: false,
contentType: "application/x-www-form-urlencoded", //This is what made the difference.
});
request.success(function(result) {
var value = JSON.stringify(result);
alert(value);
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
}
如何摆脱这种“ proto ”