当我尝试使用 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/