【发布时间】:2011-03-16 06:22:12
【问题描述】:
我的 ajax 调用看起来像这样:
$.ajax({
type: "POST",
url: "/Home/GenerateExportReport",
data: "{ 'fromDate': '2004-12-01', 'toDate': '2011-12-01', 'requestorId': = '1'}",
async: false,
cache: false,
dataType: "json",
//contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("success");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown + " text:" + textStatus + "request " + XMLHttpRequest);
}
});
我的控制器:
[HttpPost]
public ActionResult GenerateExportReport(string data)
{
. . .
}
调用正常,但由于某种原因,控制器没有收到 JSON 数据,string data 在每次调用时都为 NULL。
我确实从这个链接尝试了一些修复
从该链接修复jQuery.ajaxSetup() JQuery 1.5 and new "Text JSON" datatype 没有帮助
修复 contentType:"application/json; charset=utf-8",来自该链接 Sending String Data to MVC Controller using jQuery $.ajax() and $.post()
也没有用,当我设置 contentType: "application/json; charset=utf-8" 时,我收到错误代码 500 内部服务器错误
正如其中一篇帖子 jQuery 1.5.1 breaks all ajax() calls 中提到的那样,它可能是 jQuery validation plugin,所以目前我确实从我的页面中删除了对该脚本的引用。
有什么想法吗?
附言
数据中的字符串 ({ 'fromDate': '2004-12-01', 'toDate' ... }) 只是一个示例,我有非常大的 JSON 字符串需要传递给控制器:
["ONE", "0", "1", "0", "0", "0", "0", "0", "0", "1", "TWO", "281", "5174", "70", "3406", "1405", "300", "4632", "1522", "16790", "TREE", "13", "174", "4", "119", "32", "18", "94", "45", "499", "FOUR", "28", "931", "17", "755", "414", "17", "1138", "353", "3653", "FIVE", "2", "30", "0", "12", "8", "0", "12", "3", "67", "SIX", "13", "250", "7", "173", "77", "18", "247", "49", "834", "9am", "0", "2", "0", "0", "0", "0", "1", "1", "4", "SEVEN", "185", "2838", "45", "2100", "828", "314", "2324", "1223", "9857", "EIGHT", "173", "3662", "23", "1798", "612", "95", "2007", "445", "8815", "NINE", "308", "5277", "52", "3800", "1842", "154", "5548", "1910", "18891", "TEN", "17", "233", "3", "145", "69", "21", "199", "70", "757", "Total", "1020", "18572", "221", "12308", "5287", "937", "16202", "5621", "60168"]
【问题讨论】:
标签: jquery