gpt4 book ai didi

c# - 为什么当我使用 stringify 发布 html 时会发生此 ajax 错误

转载 作者:行者123 更新时间:2023-11-28 09:44:54 24 4
gpt4 key购买 nike

当我尝试使用 stringify 在字符串中发布 html 时,为什么会发生此 ajax 错误。

看起来 stringify 会自动转义字符。

我必须逃跑吗?谢谢

var s;

//s = "my test test"; //if I post this it works

s = "my test test<br />"; //if I post this it break when I add the html

var a = { "myText": JSON.stringify(s) };

$.ajax({
type: "POST",
url: "test.aspx",
data: a,
success: function (data) {

//pass

},
error: function () {
alert("error");

}
});

然后在页面加载时我尝试使用

读取发布的数据
HttpContext.Current.Request.Form("myText")

最佳答案

试试这个:

var s = "my test test<br />",
a = { "myText": s };
a = JSON.stringify(a)
$.ajax({
type: "POST",
url: "test.aspx",
data: a,
success: function (data) {
//pass
},
error: function () {
alert("error");

}
});

关于c# - 为什么当我使用 stringify 发布 html 时会发生此 ajax 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11907594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com