With the depth of learning, and the richness of programming experience, there is some understanding of BS applications.
In some chat software technology QQ Group, or some community, BBS, often some beginners will make some cognitive errors. For example, some friends often ask these questions: "How do I call this JavaScript function I wrote in ASP?" "or" How do I call my DAL layer to read data in JavaScript? ”
To these questions, to tell the truth, I also committed, at that time also tangled. Now think about the fact that the program for the BS structure does not have a whole concept, or that you can say that you do not know what is called a BS structure application. Therefore, the learning process will take a lot of detours, experienced a lot of pain.
After these years of study, have some experience, and share with you.
To understand the concept of BS, you must start with the origin of the BS application.
A BS application is also known as a Web application. In fact, the first web is not an application, it's just a service, a service that shares information.
What the Web is, is the net, is the network. The first network simply provides a service to download and open the remote paging file, where people can view the files that are shared on the computer by means of the address and the path to the file saved on the remote computer. These files are usually a page of text content, the path to which it is accessed in the network is called Uniform/universal Resource Locator (URL, Uniform Resource Locator).
Later people in the page added hyperlinks, so that visitors can easily access other relevant file resources. Thus, from the perspective of the page we visited from a page into a number of pages, but also laid the "Web page" this name.
With the development of the Web, the Web page has added multimedia elements such as pictures, animations, sounds, and videos that are beyond the concept of text and have a markup language that regulates the elements of these pages, making them more reasonably visible on the user's screen. So this language is called Hypertext mark-up Language (HTML, Hypertext Markup Language), which has an extension of HTML or HTM (as well as other products such as shtml). A program that specifically understands this language and gives users the perfect web content is called a browser.
Later, people found that as the content of the page is rich, sometimes many pages of the structure is exactly the same, but the content is different. This way, if you provide a lot of web files, not only waste the computer hard disk space, but also very difficult to maintain. So someone came up with a way to dynamically generate Web pages in a remote computer (Web server) to solve this problem. In this way, a Web page with a common page structure can be saved on the hard disk, and when the user requests to view the information, the Web server will extract and generate a final page content based on the file address (URL) requested by the user, and pass it back to the requestor, who receives it and opens it like a normal file.
1//(note: These dynamically generated Web pages of the technology, the earliest have CGI, later appeared asp,php,jsp,aspx, etc.)
1/*
2 (note: Here, to put special emphasis on, that is, every BS structure application developers have to keep in mind that the user (the requesting sender, or the browser, the client) requests to the remote computer, the request is always a file resource (later Ajax technology can get a piece of text), can be a Web page file , picture files, animation files, sound files, etc.)
3 */
At this point, for the user page content is not rich (with multimedia), for the server page can also be dynamically generated (easier to manage). But the drawback is that although there is a very cool page effect, but there are too few elements of user interaction. People always want to take the initiative to control some good things, and such a page in addition to click on the hyperlink, we can not do more to it.
This seems a bit of a disappointment, but it is not a problem for the wise working people. Web developers have researched a script code that can be interpreted by the browser (a very large variety of script code, most typically JavaScript), which can be used as the content of the page directly into the Web page file, or as a similar image of external resources to be introduced into the page.
With these page scripts, our web instantly became flashy. We can use the mouse to perform clicks, double-clicks, drag-and-drop operations like normal WinForm programs (with these actions, many browser events are derived).
Thus, the entire technical system of our BS application has become perfect.
Throughout the development of the BS application, each of the relevant technologies mentioned above acts as a distinct, functional module. It all revolves around the main thread of "enabling users to get information remotely." The server uses Dynamic Web-page programs to generate Web pages of different content, and to provide external resources such as related images, HTML is to link external resources, and to mark how the elements in the page are organized; The browser is responsible for requesting the server to fetch the contents of the Web page and other external resource files associated with it, to understand the structure of the page. and the obtained content (text content or multimedia content) organized, more beautiful presentation to the user; The script in the page is saved in the page as the auxiliary content of the page, and responds to the user's actions in a timely manner, performing some actions in the browser.
Let's take a look at the entire process of the browser making a request to the server:
1. First, the browser requests the server
2. The server receives a request for a browser
3. The server notes the URL of the browser request and determines the requested target resource file based on the URL. This resource file is usually the network address of a dynamic page (such as a file such as Asp,php,jsp,aspx) (a program exception to the MVC structure). The Web server generates an HTML page by invoking the appropriate resource (database or file) to organize the data based on the contents of the dynamic paging file, and the parameters in the URL. (Note that this generates an HTML document, which may contain JavaScript code, etc., in the server-side regardless of the contents of the HTML document)
4. After the HTML document is generated, the server responds to the browser's request to send the generated HTML document to the browser
5. The browser receives the requested HTML document
6. The browser notes the HTML document and requests the relevant resource files (JS,CSS, multimedia resources, embedded pages) and so on. (When the browser finishes the HTML document, it renders, but also sends a request to the server to request other related resource files)
7. After the server receives a request from the browser for the resource file, it responds to the browser with the corresponding resource file
8. The browser receives the requested resource file, organizes and renders it to the page
9. When the page is rendered, the browser executes the HTML document from top to bottom, and when the corresponding page script is encountered, the script is parsed and the corresponding script code is interpreted.
In fact, after the 6th step, we can see a portion of the page content, but may be plain text content, no style, no pictures or other resources. The organization renders when the browser requests a resource. The entire page is displayed until it finishes.
In the end, however, it is important to understand that, on the server side, HTML is processed as a text file, including scripts in HTML, which are treated as text by the server-side program. To the browser, when rendering HTML to execute a JavaScript script, is purely a separate applet, the program's running boundary is the browser, that is, it is impossible to run beyond the browser. The interaction between the browser and the server can only be done using the "request" + "response" mode, and the asynchronous interaction technology in Web development Ajax also uses this pattern to communicate information to the server.
A: The server and the browser are theoretically running on two different computers, so they cannot share variables or methods in memory. And they're not running at the same time, so it's not possible to share this data.
In-depth understanding of BS structural applications