Beginning Ajax with PHP From Novice to Professional phần 7

Tham khảo tài liệu 'beginning ajax with php from novice to professional phần 7', 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ả | 116 CHAPTER 7 A REAL-WORLD AJAX APPLICATION Next is a function called refreshView. This function is used to reload the gallery. It does this by reloading the main image container and then reloading the navigation strip. Since this needs to be done in several places we made a function out of it when an image is uploaded and when an image is deleted . The function works by using Ajax to reload the and scripts. We put each of these calls into the JavaScript setTimeout function which means the browser waits the time specified by refreshrate before loading those scripts. function refreshView Reload the full-size image. setTimeout runajax middiv refreshrate Reload the navigation. setTimeout runajax picdiv refreshrate As shown in when the user uploads an image the uploadimg function is called. The code for this function shown following first updates the status to the user to indicate that something is occurring. Next the form is submitted to the hidden iframe . the image is uploaded and finally the gallery is refreshed. function uploadimg theform Update user status message. updateStatus Now submit the form. And finally update the display. refreshView Next the removeimg function which is called when a user clicks the Delete link beside a gallery image is defined. This function simply uses Ajax to load the script which we will look closer at shortly and then refreshes the gallery. function removeimg theimg runajax errordiv pic theimg refreshView CHAPTER 7 A REAL-WORLD AJAX APPLICATION 117 Last is the imageClick function which is called when an image is clicked from the gallery navigation. These function calls could be embedded directly into each image s onclick event but instead a separate function that cleans up the code has been created. This code simply refreshes the gallery with the clicked image as the image that is to be selected. function imageClick img updateStatus .

Không thể tạo bản xem trước, hãy bấm tải xuống
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.