我们可以使用JavaScript执行服务器端代码吗? [英] Can we execute server side code using JavaScript?

查看:96
本文介绍了我们可以使用JavaScript执行服务器端代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在JavaScript中执行服务器端代码?如果是,怎么办?

Is it possible to execute server-side code in JavaScript? If yes, how?

推荐答案

JavaScript不是服务器端,而是客户端(浏览器)端.

它可以通过称为AJAX的方法调用服务器端方法(以服务器端语言,例如C#,PHP编写).

在Google上搜索AJAX教程.我个人对某些Ajax使用jQuery- http://api.jquery.com/category/ajax/ [ ^ ]
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/[^]


基本上您需要AJAX.

AJAX(XmlHttpHandler)是浏览器随附的对象,可用于使用Javascript调用Web请求.

有关更多详细信息,请使用:
AJAX教程 [ ^ ]

干杯.
:rose:
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:


目前尚不清楚您要做什么.但是,问题的答案-可以在JavaScript服务器端运行"是是".有一个称为MS脚本控件的COM对象.这允许执行任何值JScript或VBScript几乎与使用csript从命令行运行相同.

因此,在Windows上,没有什么可以阻止您创建此对象的实例,然后从支持COM的_any_服务器语言中以该对象执行代码(甚至是php-我已经做了类似的事情). JScript几乎是JavaScript的一种,并且符合标准(据我所知).因此,该解决方案将为您提供帮助.

综上所述,JScript.net http://msdn.microsoft.com/en-us/library /3bf5fs13.aspx [ ^ ]是.net语言,因此您应该可以直接在aspx中使用它.我似乎记得一个人可以直接在旧版asp中使用jscript-但我从未使用过.

尽管如此,我怀疑您可能_want_ javascript以某种类似于在客户端上运行的方式在服务器上执行.这可能会使您感到困惑.因此,正如我所说,这个问题并不是100%明确的.
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.


这篇关于我们可以使用JavaScript执行服务器端代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆