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 PrintService, which returns me the HTML to inject into a 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 the ".d" in another example
So, it works - but why? What is this ".d" ?
Apologies if this is a noob question, but google is not being my friend here.
Thanks
Edit: Magnar is right, it is a .NET specific thing. Check out Rick Strahl here - .aspx
What confuses me is that it MUST return JSON as my client script code is quite happy about the return, but when I access the browser I get XML... ?
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 PrintService, which returns me the HTML to inject into a 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 the ".d" in another example
So, it works - but why? What is this ".d" ?
Apologies if this is a noob question, but google is not being my friend here.
Thanks
Edit: Magnar is right, it is a .NET specific thing. Check out Rick Strahl here - http://www.west-wind.com/weblog/posts/164419.aspx
What confuses me is that it MUST return JSON as my client script code is quite happy about the return, but when I access the browser I get XML... ?
Share Improve this question edited Dec 21, 2019 at 22:37 Mickael Lherminez 6951 gold badge11 silver badges30 bronze badges asked Apr 11, 2009 at 10:50 DuncanDuncan 10.3k14 gold badges66 silver badges96 bronze badges 4- 1 You are asking for JSON in your ajax-call, and the web service framework seems to support that. When you access the URL through the browser, you are not specifically asking for JSON, and thus get the default XML. – Magnar Commented Apr 11, 2009 at 11:56
- Also, if you want to see the response from the server to the actual ajax-call, you can do so using the Console-panel of Firebug. Just expand the POST-call in the log and look at the Response-tab. – Magnar Commented Apr 11, 2009 at 12:04
- You may find this article of use - encosia.com/2009/02/10/… – Russ Cam Commented Apr 11, 2009 at 12:30
- related: stackoverflow.com/questions/830112/what-does-d-in-json-mean – Ruben Bartelink Commented Sep 21, 2012 at 1:42
2 Answers
Reset to default 15The 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
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