chúng ta đang quay trở lại các yếu tố hình thức đang được thay thế. Drupal biết đây là một mảng renderable và làm cho nó giá trị thích hợp. Drupal gửi HTML cập nhật trở lại trang Drupal AJAX xử lý lấy những thay đổi và thay thế các wrapper. | Chapter 10 The callback function hello_world_simple_form_callback passes the form and form_state variables after they have gone through hello_world_ simple_form_example . In this case we are returning the form element that is being replaced. Drupal knows this is a renderable array and renders it to the appropriate value. Drupal sends the updated HTML back to the page where the Drupal AJAX handlers retrieve the changes and replace the wrapper. AJAX automatically applied AJAX can be automatically applied to elements on a page. This is done by applying the use-ajax class to an element on a page. A typical use would be to apply the use-ajax class to a link within a page to trigger an AJAX action. Links are commonly used because the page the link points to might be for the cases when JavaScript is disabled as a fallback. In the following example we are going to provide a link that when clicked will add Hello World to a div within the page. To start we have two menu callbacks that we add to hello_world_menu . One item for the page we are generating and the other is the callback URL used for AJAX or when JavaScript is disabled. items hello_world link array title Hello World Link page callback hello_world_link access callback user_access access arguments array access content items hello_world_link_callback array page callback hello_world_link_response access callback user_access access arguments array access content The first menu item is to our page where the link is located and where the AJAX will add content. The second menu item is the callback that will handle the AJAX request or the page request when JavaScript is unavailable. function hello_world_link drupal_add_js misc link l t Say Hello hello_world_link_callback nojs array attributes array class array use-ajax return div . link . div div id saying-hello div 307 JavaScript in Drupal The page callback where the link lives starts by using drupal_add_js to add misc . This JavaScript does the work to .