【发布时间】:2016-09-14 02:31:50
【问题描述】:
这是 ajaxhello.js 函数 :aFunction,它从 ajax.php 返回游戏周值
function aFunction(){
var gameweekVal = 1;/*This is a random value, which is used to make the db call during ONLOAD */
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var PageToSendTo = "ajax.php?";
var VariablePlaceholder = "gameweekVal=";
var myVariable = gameweekVal;
var UrlToSend = PageToSendTo + VariablePlaceholder + myVariable;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var dataReturn = xmlhttp.responseText;
var ret= document.getElementById("currentgameweek").innerHTML = dataReturn;
getFixtures(dataReturn); /*The dataReturn vale is passed to the getFixtures(aVal) This value should then be passed to ajax2.php and used to as a select value in the SQL statement. It's not working, why ? */
}
};
xmlhttp.open("GET", UrlToSend, true);
xmlhttp.send();
}
function getFixtures(aVal){
var gameweekVal = aVal;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var PageToSendTo = "ajax2.php?";
var VariablePlaceholder = "gameweekVal=";
var myVariable = gameweekVal;
var UrlToSend = PageToSendTo + VariablePlaceholder + myVariable;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var dataReturn = xmlhttp.responseText;
document.getElementById("ajaxfixtures").innerHTML = dataReturn;
}
};
xmlhttp.open("POST", UrlToSend, true);
xmlhttp.send();
}
/******************************************************/
enter code here<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include 'configuration.php';
include 'connectTodb.php';
/* include 'dataformat.php'; */
$sqli_query= " SELECT `gameweek` FROM `gameweeks` WHERE now() BETWEEN `start`AND `end`";
$result= mysqli_query($connection,$sqli_query);
while($row= mysqli_fetch_array($result))
{
print($row['gameweek']);
}
?>
</body>
</html>
/****************************************************************/
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include 'configuration.php';
include 'connectTodb.php';
/* include 'dataformat.php'; */
$sqli_query= " SELECT `gameweek` FROM `gameweeks` WHERE now() BETWEEN `start`AND `end`";
$result= mysqli_query($connection,$sqli_query);
while($row= mysqli_fetch_array($result))
{
print($row['gameweek']);
}
?>
</body>
</html>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include 'configuration.php';
include 'connectTodb.php';
$gameweekValIn = $_REQUEST['gameweekVal'];/* The value is being passed when gameweekVal is enclosed in double quotes */
print("<table border='1'>");
$sqli_query = "SELECT `gameweek`,`home_team_id`,`home_team`, `away_team` FROM `fixtures` WHERE `gameweek`=".$gameweekValIn;
$result= mysqli_query($connection,$sqli_query);
print("<tr><th></th><th>$hash_symbol</th><th>$home_teamColHeading</th><th>$white_space</th><th>$white_space</th><th>$white_space</th><th>$away_teamColHeading</th><th>$white_space</th><th>$white_space</th><th>$white_space</th></tr>");
while($row= mysqli_fetch_array($result))
{
print("<tr><td ".$row['gameweek']."></td><td>".$row['home_team_id']."</td>"."<td>".$row['home_team']."</td>"."<td>$Letter_P</td>"."<td>$Letter_S</td>"."<td>$Letter_H</td>"."<td>".$row['away_team']."</td>"."<td>$Letter_P</td>"."<td>$Letter_S</td>"."<td>$Letter_H</td>"."</tr>");
}
print("</table>");
mysqli_close($connection);
?>
</body>
</html>
我已经包含了 ajaxhello.js,第一个函数 aFunction() 用于从 ajax.php 获取 gameweek 值,该值被传递给 getFixtures(aVal),它应该能够将其用作选择器ajax2.php
【问题讨论】:
-
这里有问题吗?
-
第 1 步:打开浏览器的开发者/网络控制台,查看/确认正在发送/接收的请求和响应。
标签: javascript php mysql ajax recursion