javascript 客户端与服务器端基础知识

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7407374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:01:45  来源:igfitidea点击:

Client side vs server side basics

phpjavascript

提问by Aly

For the last 6 months I have been trying to wrap my head around Web development and understanding the diferences beetween client-side programming and server side programming.For the moment I only know the client side at an medium level(javascript/jQuery) but I am also interested in learning PHP and MySQl for server-side programming.

在过去的 6 个月里,我一直试图围绕 Web 开发并理解客户端编程和服务器端编程之间的差异。目前我只了解中等水平的客户端(javascript/jQuery),但我我也有兴趣学习用于服务器端编程的 PHP 和 MySQl。

What are the diferences of client side programming and server side programming?

客户端编程和服务器端编程有什么区别?

When do I use client side and when do I use server side?

什么时候用客户端,什么时候用服务器端?

Those a web developer need to know both to be effective in writing website?

Web 开发人员需要知道的那些才能有效地编写网站?

回答by Shanty

Client side programming includes any coding or computation or effects or annimation or any sort of interaction your website performs with the user via browser. But server side programming is that which performs all the task in the server only. So the user is unaware of that.

客户端编程包括您的网站通过浏览器与用户进行的任何编码或计算或效果或动画或任何类型的交互。但是服务器端编程只是在服务器中执行所有任务。所以用户不知道这一点。

For example, PHP is used for server side programming. You design a website with HTML and use JavaScript in it to take some input from user and modify it in anyway. To be more specific, if you created a blog website and you want to specify that the user can post a max of 5000 characters. Then you do some client side programming with JavaScript to count the number of characters and any filtering or anything. But then you need to send those posts to the server. The server then performs some server side task, may be with PHP, to sanitize the input for SQL Injection and saves it into a database.

例如,PHP 用于服务器端编程。您使用 HTML 设计一个网站并在其中使用 JavaScript 来获取用户的一些输入并进行修改。更具体地说,如果您创建了一个博客网站并且您想指定用户最多可以发布 5000 个字符。然后你用 JavaScript 做一些客户端编程来计算字符数和任何过滤或任何东西。但是随后您需要将这些帖子发送到服务器。然后服务器执行一些服务器端任务,可能是使用 PHP,清理 SQL 注入的输入并将其保存到数据库中。

User will only know what happened in the browser but not what happened in the server. Those are background tasks.

用户只会知道浏览器中发生了什么,而不会知道服务器中发生了什么。这些是后台任务。

回答by Majid Fouladpour

For a web application you need both.

对于 Web 应用程序,您需要两者。

Best way to learn is trying to create a simple app. Consider a very simple address book app. You need to store the entries (so you need MySQL for instance).

最好的学习方法是尝试创建一个简单的应用程序。考虑一个非常简单的地址簿应用程序。您需要存储条目(例如,您需要 MySQL)。

Actually you need to be able to perform 4 basic actions with the data which is called CRUD - Create, Read, Update, and Delete. For this you need to use a language like PHP, ASP, Python, which run on your server.

实际上,您需要能够对称为 CRUD 的数据执行 4 个基本操作 - 创建、读取、更新和删除。为此,您需要使用在您的服务器上运行的 PHP、ASP、Python 等语言。

To actually use the app you need a user interface which is created by HTML + JS (or jQuery) + CSS and possibly you'd also use some images.

要实际使用该应用程序,您需要一个由 HTML + JS(或 jQuery)+ CSS 创建的用户界面,并且您可能还需要使用一些图像。

回答by Catfish

I would also add that client side code is visible to anyone viewing the web page where server side code is not visible to someone viewing the webpage.

我还要补充一点,任何查看网页的人都可以看到客户端代码,而查看网页的人看不到服务器端代码。

回答by romaninsh

Understanding of both server-side and client-side is important. Client side is in-secure, transparent and can be manipulated by user (or hacker) in any way. Server-side is protected and can't be messed around with. Any web application with user log-ins should have back-end code.

了解服务器端和客户端都很重要。客户端是不安全的、透明的,并且可以被用户(或黑客)以任何方式操纵。服务器端受到保护,不能乱动。任何具有用户登录的 Web 应用程序都应该有后端代码。

You might be able shift your code based on your requirements. For example, you can place your code primarily on the client side with Sencha / ExtJS or similar framework, then have only a simple API service on your server. You might even avoid coding for the backend completely by using some API engine.

您也许可以根据您的要求更改您的代码。例如,您可以使用 Sencha / ExtJS 或类似框架将您的代码主要放在客户端,然后在您的服务器上只有一个简单的 API 服务。您甚至可以通过使用某些 API 引擎来完全避免为后端编码。

On other hand, you can stay completely on the server-side if you pick a PHP UI Framework. Such a framework would worry about your user interface letting you use PHP only. Unlike languages such as Java and .NET There are very few UI Frameworks for PHP. I wish they would have more publicity.

另一方面,如果您选择PHP UI 框架,则可以完全停留在服务器端。这样的框架会担心您的用户界面让您只使用 PHP。与 Java 和 .NET 等语言不同,PHP 的 UI 框架很少。我希望他们能有更多的宣传。

Coding for both front-end and back-end makes development much slower, but it's a commonly accepted way right now.

前端和后端的编码会使开发速度慢得多,但这是目前普遍接受的方式。

回答by romaninsh

the short answer:

简短的回答:

client side = code runs on client machine, namely the browser
server side = code runs on server, output sent to client

客户端=代码在客户端机器上运行,即浏览器
服务器端=代码在服务器上运行,输出发送到客户端

A do it all web developer should know at least a little of both, but there are specialist in both areas.

全能型 Web 开发人员至少应该对两者都略有了解,但在这两个领域都有专家。