@green_o

Как вытащить значения переменой в PHP?

Доброго время суток, подскажите, новичку, почему не вытаскиваются данные из POST запроса?
var login= '';// логин
var password= ''; // пароль
var check_password= ''; // подверждение пароля
var check ='';



document.addEventListener('DOMContentLoaded', function() {


 document.getElementById('change').addEventListener('click', function () {

  login = (document.getElementById('login').value.toUpperCase())
  password = document.getElementById('pas').value
  check_password = document.getElementById('pas_check').value
     login = login.toUpperCase();
  var Q = hex_md5(password);


  if (password != '' && check_password != '') {
   if (password == check_password) {


 
 
		var XHR = ("onload" in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;

var xhr = new XHR();


xhr.open('POST', 'http://tests/register.php?login='+login+'&p='+password, true);

xhr.onload = function() {
  alert( this.responseText );
}

xhr.onerror = function() {
  alert( 'Ошибка ' + this.status );
}

xhr.send();






if (login == 'lal'){
    localStorage.removeItem(document.getElementById('login').value)
    var obj = { "foo": Q, "roll": 0 }
    var sObj = JSON.stringify(obj)
    localStorage.setItem("lal", sObj)
    location.reload()
}
       else{
    
}

   }


   document.getElementById('del').addEventListener('click', function () {
    window.location.reload()
    localStorage.removeItem(document.getElementById('login').value)
   })

  }
 })
})

Код PHP
<?

# Соединямся с БД


mysql_connect("localhost", "root", "");

mysql_select_db("Users");




 print "<b>ЛОГИН</b><br>";
 print  $_POST['login'];

print "<b>ПАРОЛЬ:</b><br>";
print  $_POST['p'];
?>
  • Вопрос задан
  • 194 просмотра
Решения вопроса 2
talgatbaltasov
@talgatbaltasov
Freelancer
А ты попробуй через гет вытащить print $_GET['login']
Ответ написан
Комментировать
@skyball
php программист
Так ты POST данных не отправил... читай тут

А так тебе просто надо заменить вот эту фигню:
var xhr = new XHR();


xhr.open('POST', 'http://tests/register.php?login='+login+'&p='+password, true);

xhr.onload = function() {
  alert( this.responseText );
}

xhr.onerror = function() {
  alert( 'Ошибка ' + this.status );
}

xhr.send();

на что то подобное:
var xhr = new XHR();
var body = 'login=' + encodeURIComponent(login) +
	'&password=' + encodeURIComponent(password);
xhr.open("POST", 'http://tests/register.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
  alert( this.responseText );
}

xhr.onerror = function() {
  alert( 'Ошибка ' + this.status );
}
xhr.send(body);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
КРАФТТЕК Санкт-Петербург
от 60 000 до 80 000 ₽
Brightdata Тель-Авив
от 5 500 до 6 500 $
Rocket Брянск
от 60 000 до 100 000 ₽
26 мая 2024, в 21:15
20000 руб./за проект
26 мая 2024, в 21:08
40000 руб./за проект
26 мая 2024, в 21:05
20000 руб./за проект