I
I
Igor2017-07-16 17:16:17
Drupal
Igor, 2017-07-16 17:16:17

How to pass string via ajax in DRUPAL8?

Calling a php function? Which is connected to the client side via routing.
Accordingly, in js it looks like this:

$.ajax({
          url: '/AddComment/' + msg + '/' + drupalSettings.path.currentLanguage,
          success: function (data) {
          if (data == 0) {
            // отзыв добавлен
            alert('Success!');
          } else {
            alert('Error!');
          }
          },
          dataType: 'json',
          cache: false,
          async: false
        });

msg can theoretically contain the characters "/", "\", etc. Naturally, it crashes into an error. How to pass a string so that the call passes without errors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2017-07-16
@andead

encodeURI(msg)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question