【发布时间】:2013-05-10 12:21:02
【问题描述】:
当我使用 jQuery 以以下语法发布 HTML.Form 时:
$.post('<%: Url.Action("ActionName","ControllerName") %>',
$("#FormName").serialize());
对象已正确发布到服务器,但如果我使用:
var reason = encodeURIComponent($("#FormName").serialize());
$.post('<%: Url.Action("ActionName","ControllerName") %>',
{ reason: reason });
序列化对象为空,无论使用 encodeURIComponent 或不使用它,我都会得到相同的结果。 我需要向服务器发送更多的参数数据,这就是为什么我想使用第二种方法,但我无法正确发送序列化对象。
【问题讨论】:
-
查看发布的数据(使用 Fiddler 或其他一些检查工具)会发现问题。 URI 编码单个数据点,而不是整个发布的序列化字符串。
-
谢谢,有没有其他的编码方式?
-
我很确定它已经编码的数据:stackoverflow.com/a/6653908/426894api.jquery.com/serialize
The .serialize() method creates a text string in standard URL-encoded notation. -
我检查了提琴手,正文中的区别是:reason=Type=1&Comments=&ID=15 vs Type=1&Comments=&ID=15 我的服务器端调用中的预期变量名称是“原因”。所以看起来序列化的字符串应该以某种方式装箱。
标签: jquery asp.net-mvc http-post