我使用 MVC3/EntityFramework 作为后端,前端通过 jquery 使用我所有的项目控制器,当您直接传递参数而不是硬编码的 URL 时,直接发布(使用 $.post)不需要数据加密。我已经测试了几个字符,我什至发送了一个 URL(这个http://www.ihackforfun.eu/index.php?title=update-on-url-crazy&more=1&c=1&tb=1&pb=1)作为参数并且有即使当您在 URL 中传递所有数据(硬编码)时 encodeURIComponent 工作得很好,也完全没有问题
硬编码的 URL ie>
var encodedName = encodeURIComponent(name);
var url = "ControllerName/ActionName/" + encodedName + "/" + keyword + "/" + description + "/" + linkUrl + "/" + includeMetrics + "/" + typeTask + "/" + project + "/" + userCreated + "/" + userModified + "/" + status + "/" + parent;; // + name + "/" + keyword + "/" + description + "/" + linkUrl + "/" + includeMetrics + "/" + typeTask + "/" + project + "/" + userCreated + "/" + userModified + "/" + status + "/" + parent;
否则不要使用 encodeURIComponent 而是尝试在 ajax post 方法中传递参数
var url = "ControllerName/ActionName/";
$.post(url,
{ name: nameVal, fkKeyword: keyword, description: descriptionVal, linkUrl: linkUrlVal, includeMetrics: includeMetricsVal, FKTypeTask: typeTask, FKProject: project, FKUserCreated: userCreated, FKUserModified: userModified, FKStatus: status, FKParent: parent },
function (data) {.......});