且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript和PHP之间的区别

更新时间:2023-12-04 11:39:52


什么是差异b / w php和javascript

What is the differene b/w php and javascript

大致类似于英语和德语之间的差异。他们可以表达大致相同的东西,但是以不同的方式表达,你在德国使用英语然后在英国使用德语会更幸运。

Roughly akin to the difference between English and German. They can express largely the same things, but do so in different ways, and you'll have more luck using English in Germany then German in England.


我知道一个是服务器端脚本,另一个是浏览器端

i know one is server side scripting and the other is browser side

不是真的。

PHP是一种编程语言。它通常用于服务器端编程,但也用于通用编程。

PHP is a programming language. It is often used for server side programming, but has uses in general programming too.

JavaScript是一种编程语言。它是唯一一种在浏览器中运行时具有相当级别的本机支持的语言。它有各种各样的服务器端实现(包括Node和ASP)。它是您可以与Windows Scripting Host一起使用的语言之一。等等。

JavaScript is a programming language. It is the only language that has a decent level of native support for running in a browser. It has a wide variety of server side implementations (including Node and ASP). It is one of the languages you can use with the Windows Scripting Host. etc.

还有很多其他语言可用于服务器端Web编程(C#在ASP.NET中很流行,我更喜欢Perl,有很多Python和Ruby的支持者,Java有很强的追随者,等等。)

There are plenty of other languages that can be used for server side web programming too (C# is popular in ASP.NET, I'm rather fond of Perl, there are quite a lot of proponents of Python and Ruby, Java has a strong following, and so on).

这就是说。支持PHP的El Cheapo托管比支持其他东西的El Cheap托管更常见。抛开语言党派偏见,它的主要缺点是El Cheapo托管是你得到你支付的规则。

That said. El Cheapo hosting which supports PHP is a lot more common than El Cheap hosting which supports other things. Leaving language partisanship aside, the primary disadvantage with it is that El Cheapo hosting is has the You Gets What You Pay For rule.

如果我们把你的问题提到关于服务器端和客户端编程之间的区别虽然...

If we take your question to be about the difference between server side and client side programming though…


但问的是使用客户端编程我可以显示警报消息

but what m asking is that using client side programming i can display alert messages

使用客户端编程,您可以在浏览器中操作内容而无需返回服务器。例如您可以向文档添加元素以显示消息。

With client side programming you can manipulate things in the browser without going back to the server. e.g. you can add elements to the document to display a message.

您还可以访问浏览器提供的API,例如 alert() 方法将显示一个不是文档固有部分的消息框和本地存储(允许您在浏览器中存储只有该浏览器可以访问的数据)。

You also have access to APIs provided by the browser, such as the alert() method which will display a message box that isn't an intrinsic part of the document and Local Storage (which lets you store data in the browser which only that browser will have access to).

您可以发出HTTP请求以询问服务器(这称为Ajax)。

You can make HTTP requests to ask the server for things (this is called Ajax).


我可以简单地使用服务器端编程,而不使用任何函数

which i can simply do with server side programming also,without using any function

使用服务器端编程,你可以修改文档你正在发送到客户端,但仅在加载时发送。

With server side programming, you can modify the document you are sending to the client, but only at load time.

您可以访问共享资源(例如服务器上存在的数据库的内容)。

You can access shared resources (such as the contents of a database that lives on the server).

您无权访问 alert()方法。 (虽然你可以生成程序代码(通常在JS中),它将运行客户端并可以访问这些方法)。

You don't have access to things like the alert() method. (Although you can generate program code (usually in JS) that will run client side and will have access to those methods).


所以服务器端和客户端编程是独占的,如果我使用一个然后另一个不应该使用,或者??

so does server side and client side programming are exclusive ,like if i use one then the other one should not be used,or ??

In一般来说,任何基本功能都应该通过服务器端编程来处理。 以可行的方式为基础。客户端编程可能会中断,因为您依赖于用户正在使用的浏览器中不可用的功能,因为脚本无法加载,因为用户恰好关闭了JavaScript,或者因为用户正在尝试某些操作恶意(例如将数据传递到服务器,可能导致 XSS SQL注入问题)。

In general, any essential functionality should be handled with server side programming. Build on things that work. Client side programming can break, either because you depend on a feature that isn't available in the browser the user is using, because a script fails to load, because the user happens to have JavaScript turned off, or because the user is trying something malicious (such as passing data to the server that could cause an XSS or SQL injection problem).

客户端编程,另一方面,可以用来使用户更方便。您可以添加动画以指示正在发生的事情,在将数据提交到服务器之前检查数据(节省往返时间),定期更新页面的一部分,等等。

Client side programming, on the other hand, can be used to make things more convenient for the user. You can add animation to indicate that something is happening, check data before it is submitted to the server (saving the time of a round trip), update part of a page periodically, and so on.