TAILIEUCHUNG - Practical prototype and scipt.aculo.us part 14

Practical prototype and part 14: The information in this book is distributed on an "as is" basis, without warranty Although every pre-caution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. | 66 CHAPTER 4 AJAX ADVANCED CLIENT SERVER COMMUNICATION Since Firebug logs all Ajax requests you can see for yourself. Near the bottom of your console should be a gray box containing the URL of the request expand this box to view all the request s details as depicted in Figure 4-11. S GET http andrew book chapter4 food_type waffles line 1100 60ms Params Headers Response foodtype waffles taste delicious S GET http andrew book chapter4 breakfastphp food_type waffles line 1100 60ms Params Headers Response li At strong 3 41 pm on June 1 2007 strong I ate strong delicious waffles strong Figure 4-11. The details of our Ajax request That was fun. Let s try it again run the exact same command in the console see Figure 4-12 . Figure 4-12. What happened to the first one CHAPTER 4 AJAX ADVANCED CLIENT SERVER COMMUNICATION 67 Figure 4-12 is not quite what we expected. The time is different so the content got replaced properly. But we don t want to replace the contents of ul breakfast_history we want to add to what s already there. Typically breakfast log entries are arranged so that the most recent is first. So let s change our Ajax call so that new entries are appended to the top of the container new breakfast_history insertion top method get parameters food_type waffles taste delicious Run this code and you ll see your new entry added to the top of the list as in Figure 4-13. Each time you run this code in fact a new li will be added to the top of your ul container. Figure 4-13. New entries appear at the top. Handling Errors Our script works but it s not exactly battle-tested. It naively assumes that each request will have the two pieces of information it wants. What if something goes wrong What if our scrambled eggs fail to be tabulated We need to work out some sort of code between client and server to handle situations like these. 68 CHAPTER 4 AJAX ADVANCED CLIENT .

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.