Đang chuẩn bị liên kết để tải về tài liệu:
Publishing AJAX and PHP - part 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Một lần nữa chúng tôi thành công có thể sử dụng try / catch để xử lý các lỗi có thể xảy ra khi bắt đầu một kết nối đến máy chủ, hoặc trong khi đọc những phản hồi từ máy chủ. Một phiên bản an toàn hơn phương pháp handleRequestStateChange trông như thế này: | Client-Side Techniques with Smarter JavaScript use xmlHttp.responseXML to read an XML response as a DOM object do something with the response Once again we can successfully use try catch to handle errors that could happen while initiating a connection to the server or while reading the response from the server. A safer version of the handleRequeststatechange method looks like this function executed when the state of the request changes function handleRequestStateChange continue if the process is completed if xmlHttp.readyState 4 continue only if HTTP status is OK if xmlHttp.status 200 try retrieve the response response xmlHttp.responseText do something with the response . . catch e display error message alert Error reading the response else e .toStri ng display status message alert There was a problem retrieving the data n xmlHttp.statusText OK let s see how these functions work in action. Time for Action Making Asynchronous Calls with XMLHttpRequest 1. In the foundations folder create a subfolder named async. 2. In the async folder create a file called async .txt and add the following text to it Hello client 3. In the same folder create a file called async .html and add the following code to it DOCTYPE html PUBLIC - W3C DTD XHTML 1.1 EN http www.w3.org TR xhtml11 DTD xhtml11.dtd html head title AJAX Foundations Using XMLHttpRequest title script type text javascript src async.js script head body onload process Hello server 50 Chapter 2 br div id myDivElement body html 4. Create a file called async .js with the following contents holds an instance of XMLHttpRequest var xmlHttp createXmlHttpRequestObject creates an XMLHttpRequest instance function createXmlHttpRequestObject will store the reference to the XMLHttpRequest object var xmlHttp this should work for all browsers except IE6 and older try try to create XMLHttpRequest object xmlHttp new XMLHttpRequest catch e assume IE6 or older var XmlHttpVersions new Array MSXML2.XMLHTTP.6.0 MSXML2.XMLHTTP.5.0 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.