嗨,我有一个混合了 PHP、HTML 和 javascript/Ajax 的类项目。
要求之一是“在服务器上执行 program.php,在“?”符号后面传递 N/V 对。” 我该怎么做呢?
首先.. 我不知道 NV 对是什么,我们得到的阅读链接对它们只字未提。
我做了一个课堂活动,点击按钮后,网址会更新并在“?”之后添加内容。但当然,同样的代码不再这样做了。我的教授在解释任何事情上都很糟糕,让我们遵循他甚至不完整的错字指示。
这是我们收到的代码,他的评论试图解释该怎么做:
// startgame function
// sart button pressed check fields, if OK send to PHP via get request
function startgame(){
//Create the XMLHttpRequest Object
var xmlhttp;
// error handling
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
http = xmlhttp;
// The PHP server script, called with N/V pair with GET request
// Using get request the NV pairs follow "?"
// execute program.php on server passing it the n/v pairs
// that follow the "?"
var url = "program.php?player1name=";
// for this example, only pass to PHP games played
// "&" separates n/v pairs
// player1name is name of algorithm player 1 is using
player1name = document.JForm.p1name.value;
player2name = document.JForm.p2name.value;
gamesplayed = document.JForm.gamesplayed.value;
sdata = url+player1name+"&gamesplayed="+gamesplayed;
// for a "real" solution, pass more data to PHP about state of game
// send get request to server with n/v pairs of screen data
http.open("GET",sdata, true);
// register with server what function to return data
http.onreadystatechange = handleHttpResponse;
// send request to server
http.send(null);
}
任何事情都会有所帮助,谢谢!