Показать сообщение отдельно
  #1 (permalink)  
Старый 02.02.2018, 14:05
Аспирант
Отправить личное сообщение для doox911 Посмотреть профиль Найти все сообщения от doox911
 
Регистрация: 01.04.2013
Сообщений: 56

Не могу получить значение переменной в php
Добрый день. Отправляю через ajax методом POST.

var request = null; 

function CreateRequest(){ 
	try{request = new XMLHttpRequest(); console.log('Запрос создан if-1');} 
	catch(trymicrosoft)
		{ 
		try{request = new ActiveXObject("Msxm12.XMLHTTP"); console.log('Запрос создан if-2');} 
		catch(othermicrosoft) 
			{ 
			try{request = new ActiveXObject("Microsoft.XMLHTTP"); console.log('Запрос создан if-3');} 
			catch (failed){request = null; console.log('Не создан');} 
			} 
		} 
}
var index;
function GetRequest(index){ 
	CreateRequest();
	index = 'index:'+index;
	var url = "send-email.php"; 
	request.open("POST", url, true); 
	request.onreadystatechange = RequestAnswer;
	console.log(index);
	request.send(index); 
} 

function RequestAnswer(){ 
		if (request.readyState == 4){
			if (request.status == 200){
				console.log(request.readyState);
				console.log(request.status);
				var answer = request.responseText;
				var elem = document.getElementById('byform__error-0');
				console.log('->');
				console.log(index);
				elem.innerHTML = answer;
			} 
		} 
}

$index = $_POST['index'];
echo $index;

Выдаёт: Notice: Undefined index: index in /home/d/doox91/doox91.beget.tech/public_html/send-email.php on line 9
Почему предупреждение и почему она вообще пуста? Спасибо.
Ответить с цитированием