【发布时间】:2013-11-24 18:08:13
【问题描述】:
如何将值从我的 javascript 游戏发送到我的 php 服务器?
if (!alive) {
if (sendData) {
$.ajax({
type:'GET',
url:'submitscore.php',
data:'?name='+person+'&score='+score,
success:function(data) {
if(data) {
alert("Score Submitted");
} else {
alert("Error - Contact Developer");
}
}
});
sendData = false;
// rest of gameover script
php代码
foreach ($_GET as $key => $value ) {
$value = mysql_real_escape_string($value);
$$key = $value;
}
mysql_query("INSERT INTO score (name,score)VALUES('$name','$score')") or die(mysql_error());
两个脚本都没有错误,我在数据库中得到一个新字段,但值为空,
我已经检查了 javascript 的变量名称,它们是正确的并保存了值。
当我通过 localhost/submitscore.php?name=name&score=2 直接调用 php 脚本时,脚本运行并保存该数据
【问题讨论】:
标签: javascript php ajax canvas html5-canvas