Skip to content Skip to sidebar Skip to footer

Returning Html From Json Webservice - What Is The ".d"?

This is one of those situations where I've had to pick up and run with a new tech without having time to learn the foundations! I have the following js function which calls out to

Solution 1:

The PrintService responds with JSON, a data transfer format based on the JavaScript Object Notation. So the data-parameter is an object, not an HTML-string. This object seems to have a member called d, containing the HTML.

If you visit the URL directly http://localhost/PrintService/PrintService.asmx/RenderPrintDialog, you should see the following:

{
    d: "<html here>"
}

with possibly other members aswell.

The curly brackets denote an object, and inside are key: value pairs delimited by commas. You can read more about json at json.org.

Exactly why it's called d is something you'll have to take up with the author of the PrintService. ;-) Maybe markup or html would be a more helpful name.

Edit

It turns out that Duncan is the author of the PrintService, and did not himself include the 'd'. Also, when visiting the URL he sees XML, not JSON. The .NET framework for web services in use responds with JSON when asked for it in the http request. The notorious d-member is added as a wrapper by that framework, in order to prevent cross site scripting.

This article explains the whole deal: A breaking change between versions of ASP.NET AJAX

Solution 2:

ASP.Net nests the JSON data in the d property because of cross site scripting attacks.

It is possible to return script code as the JSON response, and nesting the data inside the .d property makes it unparsable to the browser.

See here: JSON vulnerability

Regards K

Post a Comment for "Returning Html From Json Webservice - What Is The ".d"?"