为什么我需要使用.D由jQuery的AJAX返回的访问资料? [英] Why do I need to use .d to access data returned by jQuery AJAX?
问题描述
我已经使用了一些教程,我发现在互联网上收集了一些jQuery的AJAX code。我是新来的jQuery,并想学习如何做事更佳。我有一个同事谁放在一起使用了很多jQuery的一个美丽的网络应用程序。
我最困惑这里的事情是:它为什么要提到我的Web方法的响应时,使用.D它有什么主张
? // ASP.net C#code
[System.Web.Services.WebMethod]
公共静态字符串Hello()
{
返回(你好);
}//使用Javascript code
功能TestMethod的(){
$阿贾克斯({
键入:POST,
网址:ViewNamesAndNumbers.aspx /你好,
数据:{},
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON
成功:函数(MSG){
警报(MSG); //这不显示响应。
警报(msg.d); //这显示响应。
} //结束的成功:
})//结束$阿贾克斯
这在ASP.NET 3.5版的ASP.NET AJAX加入到prevent你被攻击这个漏洞:<一href=\"http://haacked.com/archive/2009/06/25/json-hijacking.aspx\">http://haacked.com/archive/2009/06/25/json-hijacking.aspx
(回答<一个来源href=\"http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/\">http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/)
I've put together some jQuery AJAX code using some tutorials I found on the internet. I'm new to jQuery and want to learn how to do things betters. I have a coworker who put together a beautiful web application using a lot of jQuery.
The thing I'm most confused about here is: why is it necessary to use the ".d" when referring to the response of my web method and what does it stand for?
// 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
It was added in ASP.NET 3.5’s version of ASP.NET AJAX to prevent you from being vulnerable to this exploit: http://haacked.com/archive/2009/06/25/json-hijacking.aspx
(Answer sourced from http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/)
这篇关于为什么我需要使用.D由jQuery的AJAX返回的访问资料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!