0

hi all I have a code like this

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");


    },

but it is sending me response in this FORMAT

{"{\"code\":\"Øù4\n\u0013¦é\",\"Age\":25}":"","proto":{}}

I just want remove "proto":{} or specifically to sal I want to get the output like this

"{\"code\":\"Øù4\\n\\u0013¦é\",\"Age\":25}"

will you guys please check where I am making the bug or the error

well,I am send the ajax request to the controller by this process

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);
        });

}

how to get rid of this "proto"

Dibyendu Konar
  • 175
  • 1
  • 1
  • 12
  • 1
    possible duplicate of [How to remove a property from a JavaScript object](http://stackoverflow.com/questions/208105/how-to-remove-a-property-from-a-javascript-object) – Hacketo Aug 20 '15 at 08:45
  • Without seeing what `.extend` does, it's hard to say whether `proto` is needed for your inheritance model to function. If it's not use `delete this.proto`, otherwise, you can do something like `Object.defineProperty(this, "proto", {configurable: true, enumerable: false, value: this.proto}` to hide the property from `JSON.stringify` – rich remer Jul 11 '16 at 18:42

0 Answers0