A
A
almenovr2020-05-09 11:39:38
PHP
almenovr, 2020-05-09 11:39:38

How to include php file in ajax request?

jQuery.ajax({
            url: "for_db.php",
            type: "POST",

At the moment I connect like this, but in the console I get an error:
POST almenovrus.beget.tech/index.php/for_db.php 404 (Not Found)
Why index.php is added to the request.
How can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
toxa82, 2020-05-09
@toxa82

Put a slash at the beginning of your url "/for_db.php"

N
ninja op op, 2020-05-09
@kur4chyt

$.ajax({
type: 'POST', //метод запроса
url: '/for_db.php', //ссылка на обработчик
data: { //передаваемые данные
data1: data_key
},
beforeSend: function(){
//выполняем код, который будет выполняться до отправки запроса
},
success: function(data){
var obj = $.parseJSON(data) //если ответ в формате JSON
//выполняем остальной код
},
error: function(){
alert("Ошибка подключения");
}
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question