var hiScore = 0;
var userip;
function onGameOver(){
if (-1 < score && score < 6) { doStuff(); }
if (5 < score && score < 9) { doStuff2(); }
if (8 < score && score < 15) { doStuff3(); }
if (14 < score && score < 21) { doStuff4(); }
if (20 < score && score < 27) { doStuff5(); }
if (26 < score && score < 31) { doStuff6(); }
if (30 < score && score < 36) { doStuff7(); }
if (35 < score && score < 51) { doStuff8(); }
if (50 < score && score < 69) { doStuff9(); }
PostTo();
}
function PostTo() {
$.ajax({
url:'Score.php',
type:'post',
data:{hiScore:hiScore,
userip:userip},
success:function(data){
alert('Success');
}
});
}
the $.ajax part of the code seems to break the js code. I've no idea why. Maybe I'm using it wrong.
here is the php as well.
<?php
$hiScore = $_POST['hiScore'];
$userip = $_POST['userip'];
$file = fopen('file.txt','w+');
fwrite($file, $hiScore.'\t'.$userip);
fclose($file);
?>
Any idea what is going on? The code starts working again perfectly after I remove the post code.
How it breaks: obviously there is more to the code its a game simply put the game doesn't start it just "breaks".
Code edited
It still isn't posting to the file.txt file. Thanks to baao for pointing out mistakes!
<?php?is invalid, as is the closing>. In the Javascript, thescorevariable is never defined. Did you meanhiScore? You should pass things as arguments, instead of using global variables. Global variables are a horrible idea.