我正在建立有关德国城市的网站。我正在尝试获取两个问题的无线电输入值(方向:北,南,西,东和城市人口:x> 1 000 000,x> 500 000,x> 100 000,x < 100 000)。人们选择了这些条件,然后单击“下一步”按钮(div =“ submit”)后,它将向他们显示city.php中的城市列表。
html:
<html>
<head>
<link rel="stylesheet" type="text/css" href="radio.css">
<script src="jquery.js"></script>
<script
src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?
config=TeX-MML-AM_CHTML' async></script>
</head>
<body>
<div class="container">
<h1>I'm looking for a city with:</h1>
<ul>
<li>
<input type="radio" id="f-option" name="population" value="million">
<label for="f-option">More than a million citizens</label>
<div class="check"></div>
</li>
<li>
<input type="radio" id="s-option" name="population" value="fivehundred">
<label for="s-option">More than 500 000 citizens</label>
<div class="check"><div class="inside"></div></div>
</li>
<li>
<input type="radio" id="t-option" name="population" value="hundred">
<label for="t-option">More than 100 000 citizens</label>
<div class="check"><div class="inside"></div></div>
</li>
<li>
<input type="radio" id="o-option" name="population" value="lessthanhundred">
<label for="o-option">Less than 100 000 citizens</label>
<div class="check"><div class="inside"></div></div>
</li>
<div id="direction">
<div class="container">
<h1>I want the city to be in the:</h1>
<ul>
<li>
<input type="radio" id="a-option" name="direction" value="north">
<label for="a-option">North</label>
<div class="check"></div>
</li>
<li>
<input type="radio" id="b-option" name="direction" value="south">
<label for="b-option">South</label>
<div class="check"><div class="inside"></div></div>
</li>
<li>
<input type="radio" id="c-option" name="direction" value="west">
<label for="c-option">Hard</label>
<div class="check"><div class="inside"></div></div>
</li>
<li>
<input type="radio" id="d-option" name="direction" value="east">
<label for="c-option">East</label>
<div class="check"><div class="inside"></div></div>
</li>
</ul>
</div>
<a href="cities.php">
<div id="submit"> Next </div>
</a>
<?php
$population = $_POST['population'];
$direction = $_POST['direction'];
?>
<script>
$(document).ready(function(){
var population = "<?php echo $population; ?>";
var difficulty = "<?php echo $direction; ?>";
$("#submit").click(function(){
$.ajax({
type: "POST",
url: 'cities.php',
data: {p: population, d: direction},
});
});
});
</script>
</body>
city.php:
$population = $_POST['p'];
$direction = $_POST['d'];
...
问题是它显示未定义索引错误:p,d