从 JSON 网络服务返回 HTML - 什么是“.d"? [英] Returning HTML from JSON webservice - what is the ".d"?

查看:18
本文介绍了从 JSON 网络服务返回 HTML - 什么是“.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!

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

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);

在我注意到 另一个例子

所以,它有效 - 但为什么呢?这个.d"是什么?

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

抱歉,如果这是一个菜鸟问题,但谷歌在这里不是我的朋友.

Apologies if this is a noob question, but google is not being my friend here.

谢谢

Magnar 是对的,它是 .NET 特定的东西.在这里查看 Rick Strahl - http://www.west-wind.com/博客/posts/164419.aspx

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

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

推荐答案

PrintService 使用 JSON 进行响应,JSON 是一种基于 JavaScript 对象表示法的数据传输格式.所以数据参数是一个对象,而不是一个 HTML 字符串.该对象似乎有一个名为 d 的成员,其中包含 HTML.

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.

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

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

{
    d: "<html here>"
}

可能还有其他成员.

大括号表示一个对象,里面是用逗号分隔的键:值对.您可以在 json.org 上阅读有关 json 的更多信息.

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

它被称为 d 的确切原因是您必须与 PrintService 的作者讨论的问题.;-) 也许 markuphtml 会是一个更有用的名字.

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.

事实证明,Duncan 是 PrintService 的作者,而他本人并未包含d".此外,在访问 URL 时,他看到的是 XML,而不是 JSON.当在 http 请求中请求时,正在使用的 Web 服务的 .NET 框架以 JSON 响应.臭名昭著的 d 成员被该框架添加为包装器,以防止跨站点脚本.

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.

这篇文章解释了整个过程:ASP.NET AJAX 版本之间的重大变化

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

这篇关于从 JSON 网络服务返回 HTML - 什么是“.d"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆