Click here to Skip to main content
15,888,337 members
Please Sign up or sign in to vote.
2.43/5 (3 votes)
See more:
Is it possible to execute server-side code in JavaScript? If yes, how?
Posted
Updated 4-Feb-10 2:23am
v2

Javascript is not server side, it's client (browser) side.

It can call server side methods (written in a server side language such as C#, PHP) by a method called AJAX.

Do a Google search for AJAX tutorials. I personally use jQuery for some of my Ajax - http://api.jquery.com/category/ajax/[^]
 
Share this answer
 
Basically you need AJAX.

AJAX (XmlHttpHandler) is an object that comes with your browser which you can use to call Web request using Javascript.

For more details use :
AJAX Tutorial[^]

Cheers.
:rose:
 
Share this answer
 
It is not 100% clear what you want to do. However, the answer to the question - "can one run javascript serverside" is "yes". There is a COM object called the MS Scripting Control. This allows execution of any value JScript or VBScript almost identically to running from the command line with csript.

Thus, on Windows there is nothing to stop you creating an instance of this object and then executing code in it from _any_ server language which supports COM (even php - I've done stuff like that). JScript is pretty much a flavour of JavaScript and is standards compliant (as far as I know). So this solution will allow what you side.

Having said all of that, JScript.net http://msdn.microsoft.com/en-us/library/3bf5fs13.aspx[^] is a .net language and so you should be able to use that directly in aspx. I seem to remember that one could use jscript directly in old asp - but I never did.

Nevertheless, I suspect you might _want_ javascript to execute on the server in some fashion similar to the way it operates on the client. Which might show up some confused thinking on your part. So, as I said, the question is not 100% clear.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900