将javascript变量传递给php变量[重复]

This question already has an answer here:

My web page

I am trying to make a highscore list. i have been seaching everywhere for an answer to this. but I can't seem to find an answer that works. yesterday I made it work yesterday. not sure which code i used think it was something like

window.location = "hihgscore_code.php=" + score

but this make it go to a new web page. i would like it to stay on my web page. then i know i have to use ajax. so i have tried post. and ajax function with the jquery but now where i want the score to stand it only becomes blank. I see no point adding my code here since it has becomed a mess after all my atempts and i am not sure what it says anymore :S

My goal is to send the score from my game made with javascript to php so that it gets the highscore list from the database and then check if the score is high enough to get on the list. then I will use <form> and <input> s to add name to the list. but for that to happen i need to get my javascript variable score into php variable :S

I hope you understand what i am trying to do if not ask. and I will try explaining it better!

i have tried window.location = "hihgscore_code.php=" + score it works but i get rerouted to http://mcclane654-productions.co.nf/game/highscore_code.php?score=7. i also most recently tried

 $.ajax({
                    type: "POST",
                    url: 'highscore_code.php',
   data: "score=" + killed})

and then used

$score = $_POST['score'];

in php to get it.

i did try a version of post yesterday in my javascript and same code in php. also tried with _GET in my php code -.-

</div>

Since no one wanted to help I found the answer my self. so if anyone else is wondering how to do this use this script:

javascript:

var htmlrequest;
if (window.XMLHttpRequest) {
htmlrequest = new XMLHttpRequest();
} else {
hmtlrequest = new ActiveXObject("Microsoft.XMLHTTP");}
htmlrequest.onreadystatechange = function() {
if (htmlrequest.readyState == 4 && htmlrequest.status == 200) {
  document.getElementById("game").innerHTML = htmlrequest.responseText;}}
htmlrequest.open("POST", "highscore_code.php", true);
htmlrequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
htmlrequest.send("score=" + killed);}

and to get it in php use

$_POST['score']

Check this out:

$.ajax({
  type: "POST",
  url: "highscore_code.php",
  data: { score: killed}
})
  .done(function( returned_data ) {

});

Variable returned_data will contain PHP output, for easy communication you should use JSON - in your PHP code echo json_encode (your data - eg. array) function, then use JSON.parse on returned_data so you will get again array of objects/object with easy access to all fields.