HTML return from JSON webservice - what is ".d"?

This is one of those situations when I had to climb and work with new technology, not having time to learn the basics!

I have the following js function that calls PrintService, which returns me the HTML to enter in the div:

function showPrintDialog() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", data: "{}", dataType: "json", url: "http://localhost/PrintService/PrintService.asmx/RenderPrintDialog", success: function(data) { $("#printdialoginner").html(data.d); 

I struggled with this FOR AN AGE before I noticed ".d" in another example

So it works - but why? What is this ".d"?

Sorry if this is a question about Nob, but Google is not my friend here.

thank

Edit: Magnar is right, this is a feature of .NET. Check out Rick Strall here - http://www.west-wind.com/weblog/posts/164419.aspx

What bothers me is that it SHOULD return JSON, as my client script code is quite happy with the return, but when I access the browser, I get XML ...?

+8
json javascript web-services
Apr 11 '09 at 10:50
source share
2 answers

PrintService responds to JSON, a data transfer format based on JavaScript object notation. So the data parameter is an object, not an HTML string. This object has a member named d that contains HTML.

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

 { d: "<html here>" } 

possibly with other members.

Curly brackets indicate an object, and inside - key: value pairs, separated by commas. You can learn more about json at json.org .

That is why it is called d - this is what you will need to discuss with the author of PrintService. ;-) Maybe markup or html would be a more useful name.

Edit

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

This article explains the whole deal: The gap between ASP.NET AJAX versions

+14
Apr 11 '09 at 11:13
source share

ASP.Net uses JSON data in the d property due to cross-site scripting attacks.

You can return the script code as a JSON response, and nesting the data inside the .d property makes it inaccessible to the browser.

See here: JSON Vulnerability

Relationship To

+4
Apr 11 '09 at 12:21
source share



All Articles