Node? Su dung ajax trong drupal nhu the nao?

Chao anh TH em dang hoc drupal muon dung no de phat trien cac ung dung web, viet module la theme.... cho no.
- Anh co the noi ro cho em biet node trong drupal la gi? no hoat dong the nao? khi lam module can quan tam den no ra sao?

Comments

Trang noi dung da viet

Ban tham khao trang nay.

The Hong

Ajax trong drupal

Anh TH cho em hoi ti.
Em co lam mot module nho, vi chua co biet cach su dung ajax trong drupal nen phai tao ajax script rieng trong module do. Nhung khi dung no de truy suat co so du lieu do cai file ajax goi. Thi cac ham lien quan toi CSDL Mysqli khong con nua(not connection, db_query khong dung duoc.) the la danh phai tao file fns.inc rieng de ket noi.

Anh noi cho em biet cach xu ly viec nay trong drupal voi! Thanks

Ajax trong Drupal (6)

Hau het cac request di den drupal site cua ban deu phai di qua /index.php => qua trinh bootstrap duoc thuc hien => cac ham chung chung, bao gom ca cac ham lam viec voi co so du lieu duoc tai len => Vay la ban goi AJAX khong dung cach roi. Cach thuc hien:

1. Trong hook_menu ban dang ky URI den kich ban tao noi dung dap tra 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;
}
?>

Da dang ky callback roi, bay gio ban can dinh nghia callback do:

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

Dang ky va dinh nghia xong roi, gio ban su dung jQuery de thuc hien request tuong tu nhu sau:

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

The Hong

load select box

Chao ban, vay khi minh dung ajax de load 1 select box, gia su co select box quan + phuong, chon quan thi se load cac phuong vao select 2, sau khi nhan submit thi drupal thong bao loi "An illegal choice has been detected. Please contact the site administrator.". Ban co cach giai quyet nao o truong hop nay ko??

Vui long kiem tra Permision,

Vui long kiem tra Permision, neu Ok, thi phai vao code xem doan do no kiem tra dieu kien gi? xem thoa mang khong? neu khong thoa mang thi vui long fix lai. than chao.

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.