O
O
Oversec2016-09-27 11:42:26
JavaScript
Oversec, 2016-09-27 11:42:26

What is the correct way to access the url when using Ajax?

I'm making ajax requests to dynamically update data, the request goes to the controller, it returns a json response. But there was such a problem that the url can be different, that is: site.ru/admin and site.ru/admin/task and site.ru/admin/task/index the same action (admin is the administrator module)

When sending request (I do this using the Post method), an error may occur if the url site.ru/admin or site.ru/admin/task.

function setComment(task_id) {

    var task_comment = prompt('Комментарий для сотрудников системы', $('.td-task-comment-' + task_id + ' span').text());
    if (task_comment == null) return;

    $.post('comment' , {task_id: task_id, comment: task_comment}, function (r) {
        if (r.success) {
            $('.td-task-comment-' + task_id).text(r.comment);
        } else if (r.fail) {
            alert(r.msg);
        }
    }, 'json');
}


Perhaps there is some way to fix this? So that requests are always sent to site.ru/admin/task/comment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-09-27
@Oversec

$.post('/admin/task/comment'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question