TAILIEUCHUNG - Phát triển Javascript - part 30

Tham khảo tài liệu 'phát triển javascript - part 30', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Making Get Requests 263 var url url url assertEquals GET url true Much better. Re-running the tests confirm that they now all pass. Moving forward we can add stubs to the fakeXMLHttpRequest object as we see fit which will make testing significantly simpler. Feature Detection and now relies on the method which is not available in the case that the browser does not support the XMLHttpRequest object. To make sure we don t provide an method that has no way of retrieving a transport we will define this method conditionally as well. Listing shows the required test. Listing Bailing out if is not available function var ajax ajax if return function get url . get With this test in place clients using the method can add a similar test to check for its existence before using it. Layering feature detection this way makes it manageable to decide what features are available in a given environment. Handling State Changes Next up the XMLHttpRequest object needs to have its onreadystatechange handler set to a function as Listing shows. Download from 264 Abstracting Browser Differences Ajax Listing Verifying that the ready state handler is assigned test should add onreadystatechange handler function url assertFunction As expected the test fails because is undefined. We can assign an empty function for now as Listing shows. Listing Assigning an empty onreadystatechange handler function get url . function To kick off the request we need to call the send method. This means that we need to add a stubbed send method to fakeXMLHttpRequest and assert that it was called. Listing shows the updated object. Listing Adding a stub send method var fakeXMLHttpRequest open stubFn send stubFn .

TỪ KHÓA LIÊN QUAN
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.