V
V
Vladislav Startsev2019-08-25 08:06:16
Drupal
Vladislav Startsev, 2019-08-25 08:06:16

Ajax requests in Drupal 7 like in WordPress, is it possible?

Trite, but yes, is it possible to build your ajax requests in drupal in the likeness of wordpress, but with a handler function in template.php? Standard tools like Drupal.ajax do not suit.
For example, in wp it is done like this:
ajax

$.ajax({
  url: ajaxurl, // ссылка обрабатываемая ajax запрос ../wp-admin/admin-ajax.php
  data: {
    'action': 'addreview', // action - действие к которому позднее прикрутиться хук/функция обработчик
    'form_data': form_data, // какие-то данные
  }, 
  type: 'post',
  dataType: 'json',
  success:function(json){} // результат
});

handler in functions.php
function clinic_add_rewiew_form(){
  // $_POST['form_data'] Что-то обрабатывает 
  die();
}
add_action('wp_ajax_addreview', 'clinic_add_rewiew_form'); // регистрирует функцию обработчик
// add_action('wp_ajax_($action)', function_name());

And actually, can I make a similar ajax request and put a similar hook handler in the template.php file of my theme and actually call Drupal core classes or module hooks in the handler.
One of the reasons why I need this is the reluctance to connect Drupal scripts, of which there are a lot and they only slow down the site, I like it when it is clean and only what is necessary on the site is used, the second is that before sending some data to the site, I need to carry out some manipulations that cannot be implemented by conventional means, if you forget about the first reason.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question