从JSON webservice返回HTML - 什么是“.d”?

时间:2022-09-15 12:54:16

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:

我有以下js函数调用PrintService,它返回我注入div的HTML:

        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

在我注意到另一个例子中的“.d”之前,我一直在努力解决这个问题

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

所以,它有效 - 但为什么呢?这是什么“.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

编辑:Magnar是对的,它是.NET特定的东西。在这里查看Rick Strahl - 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... ?

令我困惑的是,它必须返回JSON,因为我的客户端脚本代码对返回非常满意,但是当我访问浏览器时,我得到了XML ...?

2 个解决方案

#1


14  

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.

PrintService使用JSON进行响应,JSON是一种基于JavaScript Object Notation的数据传输格式。所以data-parameter是一个对象,而不是HTML字符串。该对象似乎有一个名为d的成员,包含HTML。

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

如果您直接访问URL http://localhost/PrintService/PrintService.asmx/RenderPrintDialog,您应该看到以下内容:

{
    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.

花括号表示对象,内部是键:逗号分隔的值对。你可以在json.org上阅读更多关于json的内容。

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.

正是为什么它被称为d是你必须要接受PrintService的作者。 ;-)也许标记或HTML会是一个更有用的名称。

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.

事实证明,Duncan是PrintService的作者,并没有自己包含'd'。此外,访问URL时,他看到的是XML,而不是JSON。当在http请求中询问时,正在使用的Web服务的.NET框架会响应JSON。臭名昭着的d-member被该框架添加为包装器,以防止跨站点脚本。

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

本文解释了整个交易:ASP.NET AJAX版本之间的重大变化

#2


4  

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

由于跨站点脚本攻击,ASP.Net将JSON数据嵌套在d属性中。

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.

可以将脚本代码作为JSON响应返回,并将数据嵌套在.d属性中使其无法访问浏览器。

See here: JSON vulnerability

请参见此处:JSON漏洞

Regards K

问候K.

#1


14  

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.

PrintService使用JSON进行响应,JSON是一种基于JavaScript Object Notation的数据传输格式。所以data-parameter是一个对象,而不是HTML字符串。该对象似乎有一个名为d的成员,包含HTML。

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

如果您直接访问URL http://localhost/PrintService/PrintService.asmx/RenderPrintDialog,您应该看到以下内容:

{
    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.

花括号表示对象,内部是键:逗号分隔的值对。你可以在json.org上阅读更多关于json的内容。

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.

正是为什么它被称为d是你必须要接受PrintService的作者。 ;-)也许标记或HTML会是一个更有用的名称。

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.

事实证明,Duncan是PrintService的作者,并没有自己包含'd'。此外,访问URL时,他看到的是XML,而不是JSON。当在http请求中询问时,正在使用的Web服务的.NET框架会响应JSON。臭名昭着的d-member被该框架添加为包装器,以防止跨站点脚本。

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

本文解释了整个交易:ASP.NET AJAX版本之间的重大变化

#2


4  

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

由于跨站点脚本攻击,ASP.Net将JSON数据嵌套在d属性中。

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.

可以将脚本代码作为JSON响应返回,并将数据嵌套在.d属性中使其无法访问浏览器。

See here: JSON vulnerability

请参见此处:JSON漏洞

Regards K

问候K.