我使用在互联网上找到的一些教程编写了一些 jQuery AJAX 代码。我是 jQuery 的新手,想学习如何做得更好。我有一位同事使用大量 jQuery 构建了一个漂亮的 Web 应用程序。
这里我最困惑的是:为什么在引用我的网络方法的响应时需要使用“.d”以及它代表什么?
// ASP.net C# code
[System.Web.Services.WebMethod]
public static string hello()
{
return ("howdy");
}
// Javascript code
function testMethod() {
$.ajax({
type: "POST",
url: "ViewNamesAndNumbers.aspx/hello",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg); // This doesn't display the response.
alert(msg.d); // This displays the response.
} // end success:
}) // end $.ajax
最佳答案
它已添加到 ASP.NET 3.5 版本的 ASP.NET AJAX 中,以防止您受到此漏洞的攻击:http://haacked.com/archive/2009/06/25/json-hijacking.aspx
(答案来自http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/)
关于asp.net - 为什么我需要使用 .d 来访问 jQuery AJAX 返回的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3927851/