Học JavaScript qua ví dụ part 92

Đưa It All Together Các bước chúng ta đã được tóm tắt trong các ví dụ Ajax sau đây để chứng minh làm thế nào để giao tiếp với máy chủ. Ví dụ đầu tiên cho thấy làm thế nào để sử dụng Ajax để có được thời gian của máy chủ và ứng phó với sự kiện quan trọng, hai ví dụ kế tiếp làm việc với một tập tin văn bản và một file XML, và chứng minh làm thế nào để lấy lại hiển thị nội dung của cả hai loại tập tin, và cuối cùng . | 812 Chapter 18 An Introduction to Ajax with JSON Putting It All Together The steps we have covered are summarized in the following Ajax examples to demonstrate how to communicate with the server. The first example demonstrates how to use Ajax to get the server s time and respond to key events the next two examples work with a text file and an XML file and demonstrate how to retrieve display the content of both types of files and the last example uses Ajax with forms using both the GET and POST methods. All of the programs go through the following steps 1. The user clicks a button or presses a key to initiate a function that will start the process of Ajax communicating with the server. 2. Most important JavaScript uses the XMLHttpRequest constructor method to create a new object that will serve as the Ajax communication layer between the browser and the server. If not this IFrames or cookies can be used but will not be covered in this text. 3. Once the XMLHttpRequest object is created it is initialized with the object s open method to set up the type of HTTP request GET or POST the URL where the request is going and whether the request will be asynchronous true and the default or synchronous false . 4. The request is then sent to the server with the object s send method. 5. The server processes the request and sends a response to the browser in either XML or text format. It contains the data only of the page elements that need to be changed. In most cases this data will include of just a fraction of the total page markup. 6. JavaScript processes the server response updates the relevant page content or performs another operation with the new data received from the server. Connecting to a Server Program. If you are ready to start using PHP and Apache to test these examples go to http projects xampp XAMPP and download XAMPP. It is a very easy to install Apache Distribution for Linux Solaris Windows and Mac OS X. The package includes the Apache Web

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
7    75    2    15-05-2024
7    76    2    15-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.