简体   繁体   English

使用 jquery 和经典 asp 在服务器端生成 HTML 文档

[英]generate HTML document server-side with jquery and classic asp

Here is my question,这是我的问题,

Would it be possible, knowing that classic asp support server-side javascript, to be able to generate "server side HTML" to send to the client like Response.write $(page).html()知道经典的asp支持服务器端javascript,是否有可能生成“服务器端HTML”以发送到客户端,如 Response.write $(page).html()

Of course it would be great to use jQuery to do it because it's easy to parse complicated structure and manipulate them.当然,使用 jQuery 来做这件事会很棒,因为它很容易解析复杂的结构并操作它们。

The only problem I can think of that would prevent me from doing this would be that classic asp exposes only 3 objects (response, server, request) and none of them provide "dom building facilities" like the one jQuery uses all the time.我能想到的唯一会阻止我这样做的问题是,经典的 asp 只公开 3 个对象(响应、服务器、请求),并且没有一个像 jQuery 一直使用的那样提供“dom 构建工具”。 How could we possibly create a blank document object?我们怎么可能创建一个空白的文档对象?

Edit : I have to agree with you that it's definitely not a good idea performance wise.编辑:我必须同意你的看法,这绝对不是一个明智的表现。 Let me explain why we would need it.让我解释一下为什么我们需要它。

I am actually transforming various JSON feed into complicated, sometimes nested report in HTML.我实际上正在将各种 JSON 提要转换为复杂的、有时是嵌套的 HTML 报告。 Client side it works really well, even with complicated set and long report.客户端它工作得非常好,即使是复杂的设置和长报告。

However, some of our client would like to access the "formatted" report using tools like EXCEL (using webquery which are depleted of any javascript).但是,我们的一些客户希望使用像 EXCEL 这样​​的工具(使用没有任何 javascript 的 webquery)访问“格式化”报告。 So in that particular case, I would need to be able to response.write the .html() content of what would be the jQuery work.所以在这种特殊情况下,我需要能够 response.write jQuery 工作的 .html() 内容。

I such situations I use an XML DOM as surrogate for the HTML DOM I would have in a browser.在这种情况下,我使用 XML DOM 作为我在浏览器中拥有的 HTML DOM 的代理。

jQuery can manipulating an XML DOM however jQuery expects window to be present in its context. jQuery 可以操作 XML DOM,但是 jQuery 期望 window 出现在其上下文中。 It may be possible to fool jQuery (or tweak it) so that it would work server-side but it could be quite fragile.有可能愚弄 jQuery(或调整它)以便它可以在服务器端工作,但它可能非常脆弱。

Personnally I just use a small library of helper functions that make manipulating an XML DOM a little less painful, For example as:-就我个人而言,我只是使用了一个小型的辅助函数库,它可以让操作 XML DOM 变得不那么痛苦,例如:-

function XmlWrapper(elem) { this.element = elem; }
XmlWrapper.prototype.addChild = function(name) {
    var elem = this.element.ownerDocument.createElement(name);
    return new XmlWrapper(this.element.appendChild(elem));
}

Now your page code can do:-现在您的页面代码可以执行以下操作:-

var dom = Server.CreateObject("MSXML2.DOMDocument.3.0");
dom.loadXML("<html />");
var html = XmlWapper(dom.documentElement);

var head = html.addChild("head");
var body = html.addChild("body");

var tHead = body.addChild("table").addChild("tHead");

As you create code that manipulates the DOM 'in the raw' you will see patterns you can re-factor as methods of the XmlWrapper class.当您创建“原始”操作 DOM 的代码时,您将看到可以重构为 XmlWrapper 类方法的模式。

Yes it is possible.对的,这是可能的。 No, it wouldn't be fast at all and I don't see any reason for doing it as jQuery is often used for doing things that are only relevant on the client.不,它根本不会很快,我认为没有任何理由这样做,因为 jQuery 通常用于执行仅与客户端相关的事情。

I have to ask what possible reason you have for doing this?我不得不问你这样做的可能原因是什么? If you want to build a DOM document server-side as opposed to writing HTML output, theres more likely to be an XML library of some kind that you can interface to ASP.如果您想构建一个 DOM 文档服务器端而不是编写 HTML 输出,则更有可能是某种可以与 ASP 接口的 XML 库。 jQuery is for client-side stuff, whilst server-side Javascript exists its not a common use-case. jQuery 用于客户端的东西,而服务器端的 Javascript 存在它不是一个常见的用例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC Ajax(jQuery):在服务器端生成代码? - ASP.NET MVC Ajax (jQuery): generate code server-side? 服务器端jquery - Server-side jquery 处理服务器端HTTP 4nn / 5nn错误在jQuery的ajax请求中返回整个HTML文档 - Handling of server-side HTTP 4nn/5nn errors returning a whole HTML document in jQuery's ajax requests 使用jQuery服务器端来擦除html页面 - Using jQuery server-side to scrub html pages jQuery服务器端按钮 - jQuery server-side button 当ASP.NET MVC中的客户端验证失败时,阻止jQuery服务器端调用 - Prevent jQuery server-side call when client side validation fails in ASP.NET MVC 客户端(jquery)和服务器端(asp.net)应用程序都可以访问的服务 - Service that can be accessed by both client-side (jquery) and server-side (asp.net) applications ASP.NET双列表框使用JQuery更新了客户端,以及如何在服务器端检索结果 - ASP.NET dual listboxes updated client-side with JQuery, and how to retrieve the results server-side 如何从jQuery对象文字中正确调用服务器端ASP.NET并将数据返回到jQuery - How to properly call server-side ASP.NET from jQuery object literal and return data to jQuery 创建表客户端,然后下载excel文件或在服务器端生成excel文件,保存到服务器,然后使用JQuery从那里下载? - Create table client side, then download excel file OR generate excel file server-side, save to server, and use JQuery to download from there?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM