Ajax post 无法与 .net 4 框架结合使用参数中的 html
将我们的项目升级到.net 4.0框架(从3.5开始)后,我们在参数中使用html进行ajax调用时遇到了一些问题。一旦用户在文本区域中输入一些 html,ajax 调用就不再执行。如果用户仅输入纯文本,则没有问题。
<script language="javascript">
/* Doesn't work */
var html = "<p>test</p>";
var body = "default.aspx?html=" + urlEncode(html);
var des = new AJAXInteraction(url, handleResponse, 'saveloader');
des.doPost(body);
/* Work */
var html = "test";
var body = "default.aspx?html=" + urlEncode(html);
var des = new AJAXInteraction(url, handleResponse, 'saveloader');
des.doPost(body);
</script>
有人有什么想法吗?
After upgrading our project to the .net 4.0 framework (from 3.5), we facing some problems with ajax calls with html in the parameters. As soon as the user enters some html in a text area the ajax call isn't executed anymore. If the user enters plain text only, there is no problem.
<script language="javascript">
/* Doesn't work */
var html = "<p>test</p>";
var body = "default.aspx?html=" + urlEncode(html);
var des = new AJAXInteraction(url, handleResponse, 'saveloader');
des.doPost(body);
/* Work */
var html = "test";
var body = "default.aspx?html=" + urlEncode(html);
var des = new AJAXInteraction(url, handleResponse, 'saveloader');
des.doPost(body);
</script>
Anyone any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许将页面指令中的
validateRequest
设置为 false 可以解决您的问题。在您要发布到的页面中执行此操作:默认情况下,ASP.NET 检查 HTML 代码等潜在危险输入的请求并阻止此类请求。请记住,禁用请求验证时您必须自己清理输入!
您可以在这里阅读更多相关信息: http://www.asp.net/learn/whitepapers /请求验证
Probably setting
validateRequest
in your page directive to false, will solve your problem. Do this in the Page you're posting to:ASP.NET by default checks requests for potentially dangerous inputs like HTML code and blocks such requests. Keep in mind that you have to sanitize the input yourself when disabling request validation!
You can read more about it here: http://www.asp.net/learn/whitepapers/request-validation
在这里找到答案:http://dotnetguts.blogspot。 com/2010/06/validaterequestfalse-not-working-in-net.html。
在 ASP.NET 4 中,默认情况下,对所有请求启用请求验证,并且忽略每页的 validateRequest 设置。
要恢复 ASP.NET 2.0 请求验证功能的行为,请在 Web.config 文件中添加以下设置:
Found the answer here: http://dotnetguts.blogspot.com/2010/06/validaterequestfalse-not-working-in-net.html.
In ASP.NET 4, by default, request validation is enabled for all requests and the validateRequest setting per page is ignored.
To revert to the behavior of the ASP.NET 2.0 request validation feature, add the following setting in the Web.config file: