views:

283

answers:

6

Hi,

I have a .NET webmethod that I have called from jQuery. The method returns some HTML markup that I display within a DIV element.

Once I have the response I use

$("#div").html(result.d);

My question is, what does the .d do? I don't like using code I don't fully understand? Could I get the same result using Eval?

+1  A: 

It returns the value of the field named 'd' in the object 'result'.

This question shows an example of how the JSON might look, notice the d: field.

unwind
+1  A: 

The d is part of the result returned by your .NET code. If you look at this code you should see a variable being set with the name d. If it is generated from serialized classes, then it probably sends along a member of that class with the name d.

Marius
My method just returns a string, e.g. return "blablabla". Where is the d set?
Fermin
+4  A: 

Are you referring to the ADO.NET Data Services?

I remember hearing a presentation about the JSON returning this and I think its just a wrapper to ensure the payload is a JSON object as opposed to an array (which is the case of returning multiple entities).

Why 'd' specifically? I think I remember them saying something like 'well it had to be something'.

Clinton
A: 

As others have pointed out, it returns the "d" member of the "result" object.
If you wanted to have "d" in a variable you could use this:

var property = "d";
var value = result[property];
Greg
+4  A: 

Here is your answer-

http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/

scroll down about half way and you well get a pretty thorough explaination.

infocyde
This comment from that blog post goes into a more detailed explaination. http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/#comment-34045
Chris