我使用 JSON 对 ASP.net Web 服务使用 JQuery 进行以下 AJAX 拉取:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TestWebService.asmx/Foo",
data: "{}",
dataType: "json",
success: function(msg) {
$("#justpre").html(msg.d);
$("#precode").html(msg.d);
} } );
TestWebService 实现了一个非常简单的 WebMethod Foo(),它返回以下内容:
[WebMethod]
public string Foo() {
return "multi" + Environment.NewLine + "line" + Environment.NewLine + "comment";
}
最后,我显示结果
<pre id="justpre"></pre>
<pre><code id="precode"></code></pre>
Firefox 和 Chrome 将返回值显示为多行注释就好了。然而,IE7 将其呈现为没有换行符的单行。
FF, Chrome:
multi
line
comment
IE7:
multi line comment
我怎样才能解决这个问题?