I have a Drupal form with an AJAX submit. Additionally, I have another jQuery $.get function that sends a request every 2 minutes and inserts the response into an HTML element. The form and this JavaScript code are independent of each other, performing separate tasks. However, upon submitting the AJAX form, I notice in the console that the $.get function is continuously called. I am unsure if this behavior is normal. How can I prevent this from happening?
Here is my form:
function example_my_form($form, &$form_state)
{
$form['text'] = array(
'#title' => t('Text'),
'#type' => 'textarea',
'#rows' => 5,
'#default_value' => '',
'#attributes' => array(
'class' => array('form-control'),
'placeholder' => drupal_strtolower(t('text'))
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Send',
'#ajax' => array(
'callback' => 'example_my_callback',
'wrapper' => 'example_my_form',
'method' => 'replace',
)
);
return $form;
}
function example_my_callback(&$form, &$form_state) {
return $form;
}
function example_my_form_submit(&$form, &$form_state) {
/**
* Perform desired actions
*/
}
And here is my JavaScript function:
(function ($) {
Drupal.behaviors.NoteRemind = {
attach: function (context, settings) {
function myFunction() {
var uid = Drupal.settings.MyModule.owneruid[0];
var note = document.getElementsByClassName('notecontainer')[0];
$.get('/rest/api/notes/' + uid, function (response, status, http) {
processNote(response);
}, 'json');
function processNote(response) {
var parsedData = JSON.parse(response);
console.log(parsedData);
/**
* Add parsed data to HTML element
*/
}
};
myFunction();
setInterval(function () {
myFunction();
}, 120000);
}
};
}(jQuery));