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

查看:181
本文介绍了从JSON Web服务返回的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);

我这个奋斗了AN岁之前我注意到的另一个例子

所以,它的工作原理 - 但为什么呢?这是什么.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具体的事情。退房里克施特拉尔在这里 - <一个href="http://www.west-wind.com/weblog/posts/164419.aspx">http://www.west-wind.com/weblog/posts/164419.aspx

什么困惑我的是,它必须返回JSON作为我的客户端脚本code是相当高兴的回报,但是当我访问浏览器,我得到的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的基础上,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.

如果你直接访问网址的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>"
}

与可能的其他成员以及。

with possibly other members aswell.

大括号表示一个对象,里面是关键:值对用逗号分​​隔。你可以阅读更多有关JSON在 json.org

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的作者。 ;-)也许标记 HTML 将是一个更有用的名字。

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.

事实证明,邓肯是的PrintService的作者,并没有自己包括D。此外,访问URL时,他看到XML,JSON不是。在使用.NET框架的Web服务使用JSON响应时在HTTP请求中要求它。臭名昭著的 D -member添加为一个包装用的框架,以prevent跨站点脚本。

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

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

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