$delete_commant = l(t(‘X’), $url, array(‘attributes’ =>
array(‘onclick’ => ‘return call_ajax(123)’)));
when i put alert in call_ajax function definition, it is alerted, so i proceed to write the ajax post method, but when i click the link page getting refresh,
How to implement ajax in drupal
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);
}
drupal uses jquery by default. So why not just implement this call using http://api.jquery.com/jQuery.ajax/.
Other techniques involve using the form_api like the ahah : http://api.drupal.org/api/drupal/developer–topics–forms_api_reference.html/6#ahah