@pritchin_maxim1
Начинающий IT-Разработчик

Почему после запроса от js к php появляется undefined?

После такого js зароса
$(document).ready(function () {
	$('#id_game').change(function () {
		var id_game = $(this).val();
		if (id_game == '0') {
			$('#region_id').html('<option>- Выберите Привилегию -</option>');
			$('#region_id').attr('disabled', true);
			return(false);
		}
		$('#region_id').attr('disabled', true);
		$('#region_id').html('<option>загрузка...</option>');
		
		var url = 'assets/lib/select/get_privilege.php';
		
		$.get(
			url,
			"id_game=" + id_game,
			function (result) {
				if (result.type == 'error') {
					alert('error');
					return(false);
				}
				else {
					var options = ''; 
					
					$(result.regions).each(function() {
						options += '<option value="' + $(this).attr('region_id') + '">' + $(this).attr('name') + '</option>';
					});
					
					$('#region_id').html('<option value="0">- Выберите Привилегию -</option>'+options);
					$('#region_id').attr('disabled', false);
				}
			},
			"json"
			);
	});
});

к
<?php
header("Content-Type: text/html; charset=UTF-8");
require_once ('../../config/config.php');
$id_game = @intval($_GET['id_game']);
//$country_id = 3159;
mysqli_query($connect, "SET NAMES utf8");
$regs=mysqli_query($connect, "SELECT donate, id FROM id_donate WHERE id_game = '$id_game'");
 
if ($regs) {
    $num = mysqli_num_rows($regs);      
    $i = 0;
    $regions = []; 
    while ($i < $num) {
       $regions[$i] = mysqli_fetch_assoc($regs);   
       $i++;
    }     
    $result = array('regions'=>$regions);  
}
else {
	$result = array('type'=>'error');
}
print json_encode($result, JSON_UNESCAPED_UNICODE);
?>

из
<?php 
session_start();
require_once('./assets/config/config.php');
require_once('ayth/check.php');
?>



<!DOCTYPE html>
<html lang="en">
<head>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
	<link rel="stylesheet" href="assets/css/font-awesome.min.css">
	<link rel="stylesheet" href="assets/css/style.css">
	<meta charset="UTF-8">	
	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
	<title>Личный кабинет Russian Gamers</title>
</head>	
<body>
	<?php require_once('assets/requiure/navbar.php');?>

	<div class="container">
		<div class="row">
			<div class="col-lg-8 mx-auto text-center login_success">
				<form action="#" method="get">
					Игра:
					<select name="id_game" id="id_game" class="StyleSelectBox">
						<option value="0">- Выберите игру -</option>
						<option value="1">Minecraft</option>
						<option value="2">Garry's Mod</option>
						<option value="3">CS:GO</option>
					</select><br>
					Привилегия:
					<select name="region_id" id="region_id" disabled="disabled" class="StyleSelectBox">
						<option value="0">- Выберите Привилегию -</option>
					</select>
				</form>
			</div>
		</div>
	</div>


	<?php require_once('assets/requiure/modal.php'); require_once('assets/requiure/script.php'); ?>
	<script src="assets/js/selects.js"></script>
</body>
</html>

возвращается undefined
проблему можно увидеть на lk.russian-gamers.ru
  • Вопрос задан
  • 90 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы