Node? Sử dụng ajax trong drupal như thế nào?

Chào anh TH em đang học drupal muốn dùng nó để phát triển các ứng dụng web, viết module là theme.... cho nó.
- Anh có thể nói rõ cho em biết node trong drupal là gì? nó hoạt động thế nào? khi làm module cần quan tâm đến nó ra sao?

Comments

Trang nội dung đã viết

Bạn tham khảo trang này.

Thế Hồng

Ajax trong drupal

Anh TH cho em hỏi tí.
Em có làm một module nhỏ, vì chưa có biết cách sử dụng ajax trong drupal nên phải tạo ajax script riêng trong module đó. Nhưng khi dùng nó để truy suất cơ sở dữ liệu do cái file ajax gọi. Thì các hàm liên quan tới CSDL Mysqli không còn nữa(not connection, db_query không dùng được.) thế là đành phải tạo file fns.inc riêng đẻ kết nối.

Anh nói cho em biết cách xử lý việc này trong drupal với! Thanks

Ajax trong Drupal (6)

Hầu hết các request đi đến drupal site của bạn đều phải đi qua /index.php => quá trình bootstrap được thực hiện => các hàm chung chung, bao gồm cả các hàm làm việc với cơ sở dữ liệu được tải lên => Vậy là bạn gọi AJAX không đúng cách rồi. Cách thực hiện:

1. Trong hook_menu bạn đăng ký URI đến kịch bản tạo nội dung đáp trả cho AJAX request:

Drupal 6

<?php
/** 
 * Implementation of hook_menu
 */
function hook_menu () {
  
$items['path/to/ajax/callback'] = array (
    
'access arguments' => array ('access content'),
    
'page callback' => 'your_callback_name',
    
'type' => MENU_CALLBACK,
  );

  return 
$items;
}
?>

Đã đăng ký callback rồi, bây giờ bạn cần định nghĩa callback đó:

<?php
/**
 * Callback for your ajax request
 */
function your_callback_name () {
  
$output "I am AJAX content...";
  echo 
$output;
  
module_invoke_all ('exit');
  exit;
}
?>

Đăng ký và định nghĩa xong rồi, giờ bạn sử dụng jQuery để thực hiện request tương tự như sau:

  1. $(function(){
  2. $.get('path/to/ajax/callback', function(data){
  3. alert (data);
  4. });
  5. });

Thế Hồng

load select box

Chào bạn, vậy khi mình dùng ajax để load 1 select box, giả sử có select box quận + phường, chọn quận thì sẽ load các phường vào select 2, sau khi nhấn submit thì drupal thông báo lỗi "An illegal choice has been detected. Please contact the site administrator.". Bạn có cách giải quyết nào ở trường hợp này ko??

Vui lòng kiểm tra Permision,

Vui lòng kiểm tra Permision, nếu Ok, thì phải vào code xem đoạn đó nó kiểm tra điều kiện gì? xem thỏa mãng không? nếu không thỏa mãng thì vui lòng fix lại. thân chào.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <sup> <br> <p> <h3>
  • Lines and paragraphs break automatically.
  • Link to content with [[some text]], where "some text" is the title of existing content or the title of a new piece of content to create. You can also link text to a different title by using [[link to this title|show this text]]. Link to outside URLs with [[http://www.example.com|some text]], or even [[http://www.example.com]].
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.