$ 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 –