$ delete_commant = l(t('X'),$ url,array('attributes'=> array('onclick'=>'return call_ajax(123)')));drupal call ajax function
,當我把在call_ajax函數定義警報,它警告,所以我繼續寫的AJAX POST方法,但是當我點擊鏈接頁面得到刷新,
如何在Drupal
實現Ajaxfunction call_ajax(str){alert(str);
var url = "post.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
}
我認爲你不是初始化var http。 –
atleast它應該顯示錯誤知道,但是當我點擊X,它只是刷新頁 –
你嘗試初始化在這個例子中看起來他們正在初始化var xmlhttp; http://www.w3schools.com/ajax/ajax_aspphp .asp –