$ delete_commant = l(t('X'),$ url,array('attributes'=> array('onclick'=>'return call_ajax(123)')));
当我在call_ajax函数定义中发出警报时,它会被警告,所以我继续编写ajax post方法,但是当我点击链接页面进行刷新时,
如何在drupal中实现ajax
function 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);
}
答案 0 :(得分:0)
drupal默认使用jquery。那么为什么不使用http://api.jquery.com/jQuery.ajax/实现此调用。
其他技术涉及使用form_api,如ahah:http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah
答案 1 :(得分:0)
我认为你的onclick处理程序中返回false。但您应该了解a bit more about jQuery和Unobtrusive JavaScript。