Ok, i've been stuck on this for some time...
I have my own module where I alter the form to add my own button that returns a message from the server via AJAX. I'm stuck on the ajax part. When I click on the button, I see the url change to ../myforms/ajax But I get the same page returned as output instead of my ajax message
Here are my code snippets.
I click on the button that calls my getAjaxReply function:
function getAjaxReply(context, settings)
{
console.log("this works");
$url = this.href;
jQuery.ajax
(
{
type:'POST',
url: '/myforms/ajax',
dataType: 'json',
success:voteSaved,
data:'getAjaxReply=testingAjax',
}
)
return false;
}
In my php file, I have
function myforms_menu()
{
$items['myforms/ajax'] = array(
'title' => t('myforms AJAX'),
'type' => MENU_CALLBACK,
'page callback' => 'myforms_ajaxCallback',
'access arguments' => array('access content'),
);
return $items;
}
//the php function
function myforms_ajaxCallback()
{
if($_POST['getAjaxReply'] == 'testingAjax')
{
return drupal_json(
array(
'answer' => 'success'
)
);
}
return false;
}