我的应用程序有一个大问题。我有一个连接到 php web 服务的应用程序,并在我按下按钮时获取一些数据。唯一的问题是,我的服务没有响应我,我无法找出原因。
我想将“Windesheim”发送到我的服务器,服务器(现在硬编码)返回“Windesheim”。我没有使用该数组进行测试。我正在使用谷歌浏览器。
这是我的 .html:
<html>
<head>
<title>Ekiden</title>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="_Script.js"></script>
</head>
<body>
<input id="team" type="text"/><input id="button" type="button" value="Go" />
<div id="feedback"></div>
</body>
</html>
这是我的 .js:
$('#button').click(function() {
var team = $('#team').val();
$.POST('_Dataserver.php', {team: team }, function(data) {
$('#feedback').text(data);
});
});
这是我的.php:
<?php
header('Content-Type: application/json');
$teams = array
(
"Windesheim"=>array
(
// Naam, Leeftijd, Tijd, Afstand, Gemiddelde snelheid
1 => array ('Alfred', 20, 0, 0, 0),
2 => array ('Willem', 36, 0, 0, 0),
3 => array ('Michael', 22, 0, 0, 0),
4 => array ('Stefan', 27, 0, 0, 0),
5 => array ('Timmy', 20, 0, 0, 0),
6 => array ('Pascal', 20, 0, 0, 0)
),
"Deltion"=>array
(
// Naam, Leeftijd, Tijd, Afstand, Gemiddelde snelheid
1 => array ('Simon', 21, 0, 0, 0),
2 => array ('Manuel', 33, 0, 0, 0),
3 => array ('Stephan', 29, 0, 0, 0),
4 => array ('Marko', 42, 0, 0, 0),
5 => array ('Nick', 23, 0, 0, 0),
6 => array ('Achmed', 20, 0, 0, 0)
),
"Landstede"=>array
(
// Naam, Leeftijd, Tijd, Afstand, Gemiddelde snelheid
1 => array ('Patrick', 20, 0, 0, 0),
2 => array ('Mohammed', 18, 0, 0, 0),
3 => array ('Wilson', 19, 0, 0, 0),
4 => array ('Walie', 22, 0, 0, 0),
5 => array ('Marco', 52, 0, 0, 0),
6 => array ('Mohabie', 45, 0, 0, 0)
)
);
// Als er teams worden opgevraagd
if (isset($_POST['team']))
{
$team = $_POST['team'];
if($team == 'Windesheim')
{
//echo json_encode($teams[$team]);
echo json_encode('Windesheim');
}
}
// Als er niks wordt opgevraagd
else
{
echo '';
}
?>