0
我如何從我的javascript遊戲發送值到我的php服務器?使用ajax從畫布發送vales到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的變量名而且他們是正確的,並堅持價值觀。 ?
當我直接通過本地主機/ submitscore.php名稱調用PHP腳本=名稱&得分= 2,腳本運行和保存數據