Ajax post 无法与 .net 4 框架结合使用参数中的 html

发布于 2024-09-25 06:20:15 字数 573 浏览 0 评论 0原文

将我们的项目升级到.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜警司 2024-10-02 06:20:15

也许将页面指令中的 validateRequest 设置为 false 可以解决您的问题。在您要发布到的页面中执行此操作:

<%@ Page 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:

<%@ Page validateRequest="false" %>

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

不奢求什么 2024-10-02 06:20:15

在这里找到答案:http://dotnetguts.blogspot。 com/2010/06/validaterequestfalse-not-working-in-net.html
在 ASP.NET 4 中,默认情况下,对所有请求启用请求验证,并且忽略每页的 validateRequest 设置。

要恢复 ASP.NET 2.0 请求验证功能的行为,请在 Web.config 文件中添加以下设置:

<system.web>
 <httpRuntime requestValidationMode="2.0" />
</system.web>

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:

<system.web>
 <httpRuntime requestValidationMode="2.0" />
</system.web>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文