Answer the question
In order to leave comments, you need to log in
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');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question