views:

2345

answers:

3

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

Of course it would be great to use jQuery to do it because it's easy to parse complicated structure and manipulate them.

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?

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.

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.

A: 

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.

svinto
A: 

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.

roryf
+2  A: 

I such situations I use an XML DOM as surrogate for the HTML DOM I would have in a browser.

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.

Personnally I just use a small library of helper functions that make manipulating an XML DOM a little less painful, For example as:-

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.

AnthonyWJones