A
A
alexandrnevajno12017-12-11 13:41:59
Kohana
alexandrnevajno1, 2017-12-11 13:41:59

Kohana ajax throws Error 403. Why and how to get around?

I am developing a website using the Kohana framework. I have code that will repeat. JS and PHP code. I decided to create a class and put this code there. And then call it in those places where it is needed.
Here is the JavaScript code:

public static function tags() { ?>
  $('.input-tags-wrap input').autocomplete({
    source: function (request, response) {
      $.ajax({
        url: "/application/classes/CommonFunctions/autocompletetag",
        dataType: "json",
        data:
          {
            maxRows: 12,
            startsWith: request.term
          },
        success: function (data) {
          response($.map(data.message.data, function (item) {
            return {
              label: item.name,
              value: item.name
            };
          }));
        }, 
        error: function (data) {
          $('html').html(data.responseText);
        }
      });
    },
    minLength: 1,
    delay: 50
  });

Here is the php code (this is the function where the JavaScript code calls:
function autocompletetag() {
    if (!$_GET['startsWith'] OR ! Request::initial()->is_ajax())
      return $this->render_ajax('Invalid request', false);

    $query = 'SELECT `name`, `is_show`
                FROM  `tags`
                WHERE is_show = 1 AND name LIKE  "%' . $_GET['startsWith'] . '%" and id != 54 LIMIT 0, ' . $_GET['maxRows'];

    $result = DB::query(Database::SELECT, $query)
            ->execute()
            ->as_array();

    $this->render_ajax(array('data' => $result));
  }

I call the code like this:
<?php echo CommonFunctions::tags(); ?>
When I start typing something in my field with autocomplete, I get an error:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403

Please tell me why this is happening. And how can I get around this error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-12-11
@alexandrnevajno1

Good afternoon.
Here is the translation of the error.

Access is denied!
You do not have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403

This means that you need to check the permissions of directories and files.
For directories - 755
For files - 644
ps
When formatting the code, use special tags, not the "quote" tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question