(function ($) {
  Drupal.behaviors.addCartBehavior = {
    attach: function (context, settings) {
      $(context).find('.custom-drupal-mymodule').once('hello').on("click", function () {
        $.ajax({
          url: 'http://project.loc/cart?_format=json',
          method: 'get',
          dataType: 'html',
          headers: {'Content-type': 'application/json'},
          data: {text: 'Текст'},
          success: function(data){
            alert(data);
          }
        });
      })
    }
  };
})(jQuery);
