1) Could not make ajax $.post and $.get calls in my custom module both inline and calling from a separate file using drupal_add_js. 2) Could make call of basic js function alert inline but Could not make call when js is in separate file and included using drupal_add_js.
The custom module is not a node but it is just a form which accepts user info and make submission.
In the form there is one select box and other text boxes. The feature to implement ajax is on the change of the select box to fetch data from database and populate the text fields.
What is missing here? It sounds I have problem loading libraries. Below is just some codes from the module.
//myjquery.js file
if (Drupal.jsEnabled) {
$(document).ready(function(){
if ($("#edit-name").val() > 0){
selectchange($("#edit-name").val(), 0);}
});
function selectchange(namefieldvalue) {
/*alert(namefieldvalue);//alert only work if it is online defined as inline not as a separate file using
with drupal_add_js*/
$.get("/getdata/path/", {name:"gothere", toto:"zero"});//this call seems not working
return false;
}
}
//taken from the custom module portion of the form
drupal_add_js(drupal_get_path('module','hotel'),'myjquery.js');
$form['name'] = array(
'#type' => 'select',
'#id' => 'edit-name',
'#options' => $list,
'#attributes' => array('onchange' => 'selectchange(this.value);'),
);
$form['street'] = array(
'#type' => 'textfield',
'#default_value' => $location['street'],
'#size' => 70,
'#maxlength' => 180,
);
Comments
Comment #1
heddnMarking this as won't fixed. 5.x is no longer supported/maintained. If this is still an issue in 7.x, then please re-open.