Dan*_*don 10 asp.net jquery serialization json
我已经使用我在互联网上找到的一些教程汇总了一些jQuery AJAX代码.我是jQuery的新手,想学习如何做更好的事情.我有一个同事使用大量的jQuery组装了一个漂亮的Web应用程序.
我在这里最困惑的是:为什么在引用我的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
Run Code Online (Sandbox Code Playgroud)
Sam*_*ole 13
它是在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/)