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. How could we possibly create a blank document object?
我能想到的唯一问题就是阻止我这样做,那就是经典的asp只暴露了3个对象(响应,服务器,请求),而且它们都没有像jQuery一直使用的那样提供“dom构建工具”。我们怎么可能创建一个空白文档对象?
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. Client side it works really well, even with complicated set and long report.
我实际上是将各种JSON提要转换为HTML中复杂的,有时是嵌套的报表。客户端它工作得很好,即使是复杂的设置和长报告。
However, some of our client would like to access the "formatted" report using tools like EXCEL (using webquery which are depleted of any javascript). So in that particular case, I would need to be able to response.write the .html() content of what would be the jQuery work.
但是,我们的一些客户希望使用像EXCEL这样的工具访问“格式化”报告(使用耗尽任何javascript的webquery)。所以在那种特殊情况下,我需要能够响应。编写jQuery工作的.html()内容。
3 个解决方案
#1
2
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. It may be possible to fool jQuery (or tweak it) so that it would work server-side but it could be quite fragile.
jQuery可以操作XML DOM,但jQuery期望窗口存在于其上下文中。有可能欺骗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类的方法。
#2
0
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经常用于做与客户端相关的事情。
#3
0
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. jQuery is for client-side stuff, whilst server-side Javascript exists its not a common use-case.
我不得不问你有什么理由这样做?如果你想构建一个DOM文档服务器端而不是编写HTML输出,那么更有可能是某种可以与ASP连接的XML库。 jQuery用于客户端的东西,而服务器端的Javascript存在它不是一个常见的用例。
#1
2
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. It may be possible to fool jQuery (or tweak it) so that it would work server-side but it could be quite fragile.
jQuery可以操作XML DOM,但jQuery期望窗口存在于其上下文中。有可能欺骗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类的方法。
#2
0
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经常用于做与客户端相关的事情。
#3
0
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. jQuery is for client-side stuff, whilst server-side Javascript exists its not a common use-case.
我不得不问你有什么理由这样做?如果你想构建一个DOM文档服务器端而不是编写HTML输出,那么更有可能是某种可以与ASP连接的XML库。 jQuery用于客户端的东西,而服务器端的Javascript存在它不是一个常见的用例。