解析到节点js

时间:2016-04-01 18:52:08

标签: ajax node.js

我有一个对象:

{"description":"Κλείσε τις βάνες","closeValves":["13/21","12/31","13/12","12/32"]}

当我用ajax将它发送到节点js时,它进入router.post它转换为此

{"description":"Κλείσε τις βάνες","closeValves[]":["13/21","12/31","13/12","12/32"]} ..

为什么会发生这种情况?在节点脚本中我有router.post我需要这个

let express = require('express'); let router = express.Router();

评论时更新: 调用函数:

formEvent(json,'events/entry',valvescallback);

和AJAX函数:

function formEvent(data,module,next,e){//the request function
    e=e||false;

    console.log("form:",data)
    if( e ){e.preventDefault();}
    var url = './'+module; // the script where you handle the form input.

    $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType:'json',
        success: function (data) {
            next(data);
        },
        error:function (data) {
            next(data)
        }
   });
}

评论2更新:

没有数据来自像这样的文本类型列中的postgress SQL

{"description":"Κλείσε τις βάνες","closeValves":["13/21","12/31","13/12","12/32"]}

我正在使用它将其转换为json并解析它:

var json = jQuery.parseJSON(data.task);
json.action = 'getValves';
json.test = json.closeValves;//test to see if it also changes name

我可以看到它转换了像这样的数组的任何属性 name:[1,2,3] --> name[]:[1,2,3]

奇怪的是,当我{AJ}函数中的console.log数据时,它们的格式是正确的,但是在帖子中它们会发生变化..

1 个答案:

答案 0 :(得分:0)

我发现了!!答案是 TreeNode newNode = TreeNode.New(PageType, tree); newNode.DocumentName = mediaFile.FileName; newNode.DocumentName = fileName.Trim(); newNode.SetValue("FileDate", fileDate); DocumentHelper.InsertDocument(newNode, parentNode.NodeID); AttachmentInfo newAttachment = null; // Path to the file to be inserted. This example uses an explicitly defined file path. However, you can use an object of the HttpPostedFile type (uploaded via an upload control). string filePath = MediaLibraryPath + @"\" + mediaFile.FileName + mediaFile.FileExtension; // Insert the attachment and update the document with its GUID newAttachment = DocumentHelper.AddUnsortedAttachment(newNode, Guid.NewGuid(), filePath, tree, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE); // attach the new attachment to the page/document newNode.SetValue("FileAttachment", newAttachment.AttachmentGUID); DocumentHelper.UpdateDocument(newNode); newNode.Publish(); npm用法的定义:

body-parser

你只需要使扩展属性为true,数组名称不会改变..所以答案是

app.use(bodyParser.urlencoded({ extended: false}));