THE BOOK OF JAVASCRIPT, 2ND EDITION phần 8

Một khi bạn đã thực hiện thay đổi của bạn, bạn có thể thay thế các bảng ban đầu với người mới sử dụng replaceNode (). Giống như insertBefore () và removeChild (), phương pháp này được gọi là cha mẹ của các nút được thay thế. Với myTable và cloneTable biến được định nghĩa ở trên, bạn có thể làm điều này: | number 1 number contents Go with Nestor and Ajax to convince. contents item item number 2 number contents Play with big wooden horse contents item openitems doneitems doneitems list Figure 17-8 XML representing Odysseus s To Do list stored in The root element in this XML file list contains three elements the name of the list a list of pending items openitems and a list of completed items doneitems . As you can see in Figure 17-8 Odysseus has two tasks to complete and and has no completed tasks there s nothing between the doneitems tags in . Each task in the list has two elements a number which makes it easy to identify the item and the item itself . When Odysseus adds or changes an item s status the XML file is updated. NOTE I invented the XML tags for both and the To Do list file. If there was some generally accepted XML standard for To Do lists I could have used that instead. To Do List Server Side This example uses only two straightforward PHP programs. The first reads in an XML file it is almost a copy of the code in Figure 16-16. If a HEAD request was sent returns only the last-modified date of the file. If a GET request is sent reads the requested file from the webserver and passes it to the browser. The only difference between Figure 16-16 and is that sends an additional header when responding to a GET request header Content-Type text xml The second server-side program saves an XML file. Figure 17-9 shows the PHP code. As I hope you ll see it s very similar to the program we used to write out a text file in Creating and Adding Contents to a Text File with PHP on page 321. php o fileName _REQUEST fileName contents _REQUEST contents myFile fopen fileName w 0 success fwrite myFile stripslashes contents 336 Chapter 17 fclose myFile if success TRUE print success else print failure Figure 17-9 PHP program for saving a string to a

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
Đã 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.