Re: Which Is The Better Approach To Working With Javascript?



Patient Guy wrote:
"Twayne" <nobody@xxxxxxxxxxxxxxxxxxx> wrote in comp.lang.php:

.oO(sheldonlg)

Patient Guy wrote:
So, based on your response, you are telling me that a PHP processing
implementation has no interprocess communication capability, or
ability to interface with a (Java)script interpreter.

Hint: javascript does NOT run on the server.
A server, or a server-associated process, can start a script host,
passing some form of input to it, and the script host does the
script interpretation, while the calling process waits for output.

However this is achieved, PHP (by design?) has no script interface,
based on your response.

Here, try this on for size.

Javascript is run **ONLY** on the client.
Wrong. JavaScript is just a language and can run everywhere if an
interpreter is available. Even PHP can be run in a client's browser if
you have the required plugin (at least for IE such a plugin exists!)

In any script that puts up a
page, if there is Javascript, that script is run on the client
**BEFORE** anything is sent to the server.
Correct, but now you're talking about a particular implementation of a
JS engine and the most common use of JS. But there are also various JS
engines available that run on a server.

http://en.wikipedia.org/wiki/Server-side_JavaScript

If a php script is invoked, either via a page post or from the href
of an anchor or from an httpRequest, it is invoked on the
**SERVER**. It gathers input from the calling form in one of two
ways. It can get that from $_GET or from $_POST or both, depending
upon the method of the calling form.

PHP can then send HTML back to the client for display. PHP does
**NOT** run Javascript.
If there's a JS engine available, then of course PHP can invoke a
Java- Script like it can call a Perl script, Python, Java ...
whatever. A programming language is never restricted to just a single
environment.

Micha
I mean no offense here, but I think the original answers based on the level of the OP were probably good ones; run it client side because the server likely doesn't provide it?. Perhaps the missed point was simply that servers would have to be checked to see if they would serve js, same as checking to see if and what version of PHP they provide, if they provide it, which almost all do AFAIK. So js is normally intended to be run on the client side, not the server side.
Or am I all wet? I'm not sure I see any value to running js for the client on the server side. Seems like js could put quite a load on a server if many people used it that way, since it's so prevalent in coding these days.

I got curious so I checked my own servers and they do not provide any js capability that I could find. I didn't ask support though; I'm trying to avoid js, but it can be pretty handy for some things, I know.

There are several reasons for running it on the server side, which were all given in the post with message ID

<news:Xns9AD554BCD7E9FUVAA@xxxxxxxxxxxx>

cited in the original post.

The reason all starts with the need to convert a pseudo-math plaintext notation into MathML. The parser and generator was originally written in Javascript, and that was ported to PHP so that string input from a form textarea control could apparently seamlessly be translated to MathML all within PHP.

But I want to tweak the code of the parser and generator, and I am quite familiar with Javascript, and much less so with PHP. It would be no issue at all if I can work easily with PHP at this very moment, for I would edit the PHP code rather than the Javascript code.

From the Wikipedia reference it appears that only JAXER has any DOM capabilities, and whether it can deal with MathML you would need to investigate. I'm thinking not. Most, if not all server side JS implementations are not concerned with doing client side type stuff, it's a very different animal than client side JS. Remember that the JS you are used to using only runs through a browser, that there is no standalone client side JS.

Now, it seems to me that rather that go through all this to possibly get nowhere that learning a little more PHP would be easier. It looks a lot like javascript to me to the point that when I embed javascript in my php it's hard for me to tell which is which!

Jeff


So given that I would rather make use of the original Javascript code---
and can---then the two ways of making use of the Javascript code was either to have PHP set up the delivered document to client with the input string bundled with the Javascript code and have it all done on the client side, or to run something like wscript or cscript from the server, which is the host interpreter for J(ava)script, and then run the output to PHP for deliver (thus, all done on the server side).

Surely both approaches are possible, but which of the two is more sensible?
.



Relevant Pages

  • Re: Tier3 today - And Flex-it like NASDAQ (*Only better!*)
    ... FlexBuilder, or just working on the FABridge functionality in general, you ... ArrayCollections are completely accessible via the Javascript in ... Broadcasted server to client messages, ...
    (comp.os.vms)
  • Re: Visual Studio only debugs javascript in .js files not .aspx fi
    ... An ASPX page is a class that generates HTML ... from the server. ... including any literal JavaScript in the page code, ... is used by the client browser to execute JavaScript on the client side, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do we get there from here?
    ... > 'AJAX approach'? ... I am using php and ajax, ... linked to the page back to the server, which could be a php script. ... but is not an entire page) to the JavaScript. ...
    (comp.databases.pick)
  • Re: HELP: send binary replies back and forth ???
    ... a client, not a server. ... simple php function to set the timeout), ... Issues in writing php server are: ... >> and communication then goes back and forth between the server and client ...
    (comp.lang.php)
  • Re: Which Is The Better Approach To Working With Javascript?
    ... Server side processing: Web server gets form input, ... the Javascript module, and PHP collects the output for document prep. ... Client side processing: Web server gets form input and passes it ...
    (comp.lang.php)