Wednesday, October 13, 2010

Why do I need to use .d to access data returned by jQuery AJAX?

Programmer Question

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


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails