道场XhrPost用于在服务器上贴出的JSON对象集名称(Dojo XhrPost set name

2019-10-29 15:52发布

我有一个Dojo Ajax请求,我张贴的数据作为JSON但数据未达到JSON格式的服务器。 我也没能看到JSON选项卡浏览器控制台的网络选项。 我需要在服务器上的JSON格式的数据。

Ajax请求

 var someData = [{id:"1",age:"44",name:"John"},
                           { id:"2",age:"25",name:"Doe"},
                           { id:"3",age:"30",name:"Alice"}];

    function SendData() {

   var xhrArgs = {
        url:'processData',
        postData: someData,
         handleAs: "json",
         headers: { "Content-Type": "application/json", "Accept": "application/json" },

        load:function(data){
            console.log('data was posted');
        },
        error:function(error){
            console.log(error);
        }
    };
    dojo.xhrPost(xhrArgs);

的服务器的详细信息截图

我想JSON数据下按以下格式出现在名为MyData的。 这是怎么可能的格式在服务器上?

JSON

MyData              [Object{id:"1",age:"44",name:"John"},
                     Object{ id:"2",age:"25",name:"Doe"},
                     Object{ id:"3",age:"30",name:"Alice"}]

资源

{"MyData":[{id:"1",age:"44",name:"John"},
               { id:"2",age:"25",name:"Doe"},
               { id:"3",age:"30",name:"Alice"}]}

Answer 1:

其实网址:'在你的Ajax调用空。 请提供操作URL,

对于假设

url: "AddTrackServlet"


Answer 2:

玩弄变量后,我看到了它可能被宣布

var someData = [{id:"1",age:"44",name:"John"},
                           { id:"2",age:"25",name:"Doe"},
                           { id:"3",age:"30",name:"Alice"}];
var formData = {MyData:someData}
    function SendData() {

   var xhrArgs = {
        url:'processData',
        postData: dojo.toJson(formData),
         handleAs: "json",
         headers: { "Content-Type": "application/json", "Accept": "application/json" },

        load:function(data){
            console.log('data was posted');
        },
        error:function(error){
            console.log(error);
        }
    };
    dojo.xhrPost(xhrArgs);


文章来源: Dojo XhrPost set name for posted json object on server