weixin_33681778 2018-08-13 15:57 采纳率: 0%
浏览 54

ajax POST发送null

I originally wrote the call as a GET but found a limitation with the length of the URI. Ideally, the call will take an object and turns it into a JSON format string, then sends it to a controller which will encrypt that string. The controller will send back a true/false if it succeeded.

My problem with POST, once it reaches the controller, the data parameter set from the ajax is null.

Here is the ajax/js:

var encActionURL = '@Url.Action("Encrypt", "Home")';
$.ajax({
    url: encActionURL,
    type: "POST",
    contentType: "application/json; charset=utf-8;",
    dataType: "json",
    async: true,
    traditional: true,
    data: { jsonDoc: JSON.stringify(jsonDataFile) },
    success: /*OnSuccess*/ function (result) {
        // DO STUFF;
    }
});

Here is the controller:

[HttpPost]
public bool Encrypt(string jsonDoc)
{
    return serverConnection.Encrypt();
}

Note that, when I simply change the type to 'GET', it works great but when the form gets too long, it throws a 414 status error.

Most of the fixes found that I seem to have is the 'application/json'. I've also set ajax to traditional.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题