1

I am sending json data as a string to the server in asp.net mvc as shown in the following;

var dto = JSON.stringify(transObj);
                    console.log(String(dto));
$.ajax({
                    url: "/home/activity",
                    dataType: 'html',
                    data: "obj=" + String(dto) + "&trackedFromEntityTypeId=" + trackedFromEntityTypeId + "&trackedFromEntityType=" + trackedFromEntityType,
                    type: 'POST',
                    success: function (data) {
                        var jsonResult = JSON.parse(data);
                        if (jsonResult.status) {
                            bootbox.alert(jsonResult.message, function () {
                                window.location.href = "/";
                            });
                        } else {
                            displayError('Something bad happend. ' + data.message);
                        }
                    },
                    error: function (error) {
                        displayError('Something bad happend. ' + error.statusText);
                    },
                    complete: function () {
                        $.unblockUI();
                    }

                });

As you can see before it goes to the server, iam writing the string to the console. When i open the console window, the data shown in json format as expected but on the server the string is truncated as shown the following picture; enter image description here enter image description here However, the orignal json data in console window is shown below (as expted). i also used the jsonformatter to format the data as json and its formating the data properly;

{ "ActivityInformation" : { "Attributes" : [ { "AttributeId" : "18",
            "AttributeMappingId" : "17",
            "AttributeName" : "Number of Helpers",
            "AttributeValues" : [ { "Value" : "" } ]
          },
          { "AttributeId" : "19",
            "AttributeMappingId" : "12",
            "AttributeName" : "Thickness",
            "AttributeValues" : [ { "Value" : "" } ]
          },
          { "AttributeId" : "14",
            "AttributeMappingId" : "16",
            "AttributeName" : "Width of Trench",
            "AttributeValues" : [ { "Value" : "" } ]
          },
          { "AttributeId" : "8",
            "AttributeMappingId" : "13",
            "AttributeName" : "Extra No",
            "AttributeValues" : [ {  } ]
          },
          { "AttributeId" : "10",
            "AttributeMappingId" : "15",
            "AttributeName" : "Dozer PL.Num",
            "AttributeValues" : [  ]
          },
          { "AttributeId" : "7",
            "AttributeMappingId" : "14",
            "AttributeName" : "Shovel Plate No (Company)",
            "AttributeValues" : [ { "Value" : "51741" } ]
          }
        ],
      "Id" : "25",
      "Name" : "Formation Preperation",
      "Tools" : [ { "ToolGroupName" : "Grader  -  MG 118 - 2003 - CAT 14H",
            "Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "19",
                        "AttributeMappingId" : "21",
                        "AttributeName" : "Thickness",
                        "AttributeValues" : [ { "Value" : "" } ]
                      },
                      { "AttributeId" : "17",
                        "AttributeMappingId" : "22",
                        "AttributeName" : "Number of Masons",
                        "AttributeValues" : [ { "Value" : "" } ]
                      },
                      { "AttributeId" : "7",
                        "AttributeMappingId" : "23",
                        "AttributeName" : "Shovel Plate No (Company)",
                        "AttributeValues" : [ { "Value" : "51741" } ]
                      }
                    ] } ]
          },
          { "ToolGroupName" : "Grader  -  MG 119 - 2007 - CAT 14H",
            "Tools" : [ { "ToolAttributes" : [  ] } ]
          },
          { "ToolGroupName" : "Backhoe Loader -  BL 108 - 2007 - CAT 422E",
            "Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
                        "AttributeMappingId" : "19",
                        "AttributeName" : "Number of Helpers",
                        "AttributeValues" : [ { "Value" : "" } ]
                      },
                      { "AttributeId" : "13",
                        "AttributeMappingId" : "20",
                        "AttributeName" : "Width of Work",
                        "AttributeValues" : [ { "Value" : "" } ]
                      }
                    ] } ]
          },
          { "ToolGroupName" : "Backhoe Loader -  BL 109 - 2007 - CAT 422E",
            "Tools" : [ { "ToolAttributes" : [  ] } ]
          },
          { "ToolGroupName" : "Backhoe Loader -  BL 110 - 2007 - CAT 422E",
            "Tools" : [ { "ToolAttributes" : [  ] } ]
          },
          { "ToolGroupName" : "Backhoe Loader -  BL112 - 2006 - CAT0416",
            "Tools" : [ { "ToolAttributes" : [  ] } ]
          }
        ]
    },
  "ActivityListInformation" : { "Id" : "14",
      "Name" : "Road Activities"
    },
  "MilestoneInformation" : { "Id" : "8",
      "Name" : "Milestone 3"
    },
  "PlaceInformation" : { "AreaId" : 4,
      "AreaName" : "Area 1",
      "RoadId" : 6,
      "RoadName" : "108D",
      "ZoneId" : 5,
      "ZoneName" : "Zone 1"
    },
  "ProjectInformation" : { "Id" : "3",
      "Name" : "LEVELLING AND ROADS IN AL BARSHA SOUTH – COMMUNITY 671 & 672"
    },
  "SubActivityInformation" : [ { "Attributes" : [ { "AttributeId" : "12",
              "AttributeMappingId" : "6",
              "AttributeName" : "End Chainage",
              "AttributeValues" : [ { "Value" : "" } ]
            },
            { "AttributeId" : "18",
              "AttributeMappingId" : "7",
              "AttributeName" : "Number of Helpers",
              "AttributeValues" : [ { "Value" : "" } ]
            }
          ],
        "Id" : "1",
        "Name" : "Test Sub Activity",
        "Tools" : [ { "ToolGroupName" : "Grader  -  MG 118 - 2003 - CAT 14H",
              "Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "19",
                          "AttributeMappingId" : "21",
                          "AttributeName" : "Thickness",
                          "AttributeValues" : [ { "Value" : "" } ]
                        },
                        { "AttributeId" : "17",
                          "AttributeMappingId" : "22",
                          "AttributeName" : "Number of Masons",
                          "AttributeValues" : [ { "Value" : "" } ]
                        },
                        { "AttributeId" : "7",
                          "AttributeMappingId" : "23",
                          "AttributeName" : "Shovel Plate No (Company)",
                          "AttributeValues" : [ { "Value" : "51741" } ]
                        }
                      ] } ]
            },
            { "ToolGroupName" : "Backhoe Loader -  BL 108 - 2007 - CAT 422E",
              "Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
                          "AttributeMappingId" : "19",
                          "AttributeName" : "Number of Helpers",
                          "AttributeValues" : [ { "Value" : "" } ]
                        },
                        { "AttributeId" : "13",
                          "AttributeMappingId" : "20",
                          "AttributeName" : "Width of Work",
                          "AttributeValues" : [ { "Value" : "" } ]
                        }
                      ] } ]
            }
          ]
      },
      { "Attributes" : [  ],
        "Id" : "2",
        "Name" : "sdfdsfsdfsdf",
        "Tools" : [ { "ToolGroupName" : "Backhoe Loader -  BL 108 - 2007 - CAT 422E",
              "Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
                          "AttributeMappingId" : "19",
                          "AttributeName" : "Number of Helpers",
                          "AttributeValues" : [ { "Value" : "" } ]
                        },
                        { "AttributeId" : "13",
                          "AttributeMappingId" : "20",
                          "AttributeName" : "Width of Work",
                          "AttributeValues" : [ { "Value" : "" } ]
                        }
                      ] } ]
            },
            { "ToolGroupName" : "Backhoe Loader -  BL 109 - 2007 - CAT 422E",
              "Tools" : [ { "ToolAttributes" : [  ] } ]
            }
          ]
      }
    ]
}
4
  • Showing that view is somewhat pointless since it is always truncated - please show either output of evaluating obj in "immediate window" OR in "text view" (small arrow next to magnifying glass in your picture). Commented May 26, 2014 at 6:02
  • @AlexeiLevenkov, i added the text visualizer Commented May 26, 2014 at 6:08
  • 1
    As you've probably already figured out & is the problem. Since you are building post data by hand (instead of letting jQuery do it correctly) you need to encode each value yourself. Commented May 26, 2014 at 6:10
  • @AlexeiLevenkov you are right. the problem was the &, i solved it. Thanks for your help Commented May 26, 2014 at 6:15

1 Answer 1

1

Just figured it out with the help of @Alexei Levenkov comment. The problem was, i was preparing data manually and sending the data to the server using query string format. Howerver, the method i choose is POST. So i just prepare a javascript object and then send it as an object to the server;

var dto = { "obj": JSON.stringify(transObj), "trackedFromEntityTypeId": trackedFromEntityTypeId, "trackedFromEntityType": trackedFromEntityType };
 $.ajax({
                        url: "/home/activity",
                        dataType: 'html',
                        data: dto,
                        type: 'POST',
                        success: function (data) {
                            var jsonResult = JSON.parse(data);
                            if (jsonResult.status) {
                                bootbox.alert(jsonResult.message, function () {
                                    window.location.href = "/";
                                });
                            } else {
                                displayError('Something bad happend. ' + data.message);
                            }
                        },
                        error: function (error) {
                            displayError('Something bad happend. ' + error.statusText);
                        },
                        complete: function () {
                            $.unblockUI();
                        }

                    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.