Asp.net
為什麼我需要使用 .d 來訪問 jQuery AJAX 返回的數據?
我使用在網際網路上找到的一些教程整理了一些 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/)
Microsoft 這樣做是為了保護您免受安全漏洞的侵害。有關更多資訊,請參閱本頁底部。