我将MVC3 / EntityFramework用作后端,前端通过jquery消耗了我所有的项目控制器,直接传递(使用$ .post)不需要数据加密(当您直接传递参数而不是硬编码的URL时)。我已经测试了几个字符,甚至发送了一个URL(这个http://www.ihackforfun.eu/index.php?title=update-on-url-crazy&more=1&c=1&tb=1&pb=1)作为参数,并具有根本没有问题,即使当您在URL中传递所有数据(硬编码)时,encodeURIComponent的效果很好
硬编码的网址,即>
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) {.......});
$.param
。