Re: Using prototype to define classes accessible by both the server-side (ASP) & client-side

iporter
Sun, 13 Jan 2008 10:09:58 -0000

Thanks Matt, I appreciate your thoughts.

On Jan 11, 2:22 pm, Matt Foster
<mattfoste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> I can''t say I fully understand your troubles with ASP, maybe you
> should boycott the evil empire and move on to greener pastures?

The more I learn, the more I''m tempted.  But it would involve a bit of
a learning curve for which I don''t currently have time.

> On the idea of having a web application that initiates with database
> driven data on load and then has to interact with ajax requests to
> update the document I suggest using a common service that serves XML.
> Your asp environment will then be able to make the same call to
> extract the XML and iterate over nodes for display as the ajax request
> does.  In this way you only have one "middle tier" that interacts
with
> your data.  You have two displays though, one for Ajax, one for
> traditional web, not the best case but when you''ve got to
accommodate
> a broad audience what can ya do.

Yup, I think this is what I''m referring to when I say, ''I
guess I
could have used AJAX to get the server-side code to return the HTML.''
The problem I have with this is that I''d have to pass all the
parameters in addition to the data parameters.  For example, if I
wanted to draw a menu with a server-side menu object, I''d have to pass
the database parameters plus menu object parameters like
''sortable'',
''collapsible'', etc.  This doesn''t seem intuitive.

> Hope that helps,
>                    Matt
>
> On Jan 10, 6:40 pm, iporter
<ispor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Although some javascript objects are client-specific (i.e. document)
> > and others server-specific (i.e. Response), much of prototype.js can
> > be used on the server-side.
>
> > In building a recent application, I found myself building converting
> > database data into HTML objects on the server-side, to ensure it
> > readable by the search engines, but having to largely duplicate that
> > code for the client-side to redraw the HTML when the user updated
> > things.  I guess I could have used AJAX to get the server-side code to
> > return the HTML.
>
> > But I still need to have a client-side object, because I need to
> > unobtrusivly add client-side behaviours to the HTML.  Thus, what
I''d
> > like to be able to do, is define a class in a .js file, and then
> > inlcude that .js file with both the server-side and client-side code.
>
> > If you put the code, function test() {return 1;} in a .js file,
> > include this file in an ASP page using a <script
runat="server"> tag,
> > and after this put <% Response.Write(test()) %>, you get
''1'' on the
> > page.  However, if you add the code, var x = 2 to the .js file, and
> > put <% Response.Write(String(x)) %> in your ASP page, you get
> > ''undefined''.
>
> > Interestingly, if you then remove the code x = 2 from the .js file,
> > but leave the call in the ASP page, you get a runtime error 800a1391
> > with a message saying, ''x is undefined''.
Didn''t our test before show
> > it was already undefined?
>
> > The point being, that if functions work, but variables don''t,
then I
> > can''t use prototype''s nice, var myClass =
Class.create({}); syntax.
>
> > What gives?  Can I get around this somehow?  Or perhaps this is
> > ridiculous and you have a better approach to the problem?
>
> > Looking forward to your thoughts,
> > Iain