0

I want to post via JavaScript several vars but I can't, it doesn't do anything.

After a script is done running, I want to send the vars via POST so I can read them with "$_POST" and use them in a PHP script

Here is an example of my Script

function finish()
{
 var cnt1 = 50;
 var tim = 60;
 var hecho = 1;

$.post("index.php", { t:tim }, { m:cnt1 }, { e:hecho } );
}

I could do this:

top.location.href="index.php?e="+hecho+"&t="+tim+"&m="+cnt1;

But I don't want to use GET because users will see the Variables, I want to use POST so is a bit harder to hack.

What I am doing wrong?

4

2 回答 2

2

You just put all the variables into a single object:

$.post("index.php", { t:tim, m:cnt1, e:hecho } );
于 2013-04-17T23:17:39.623 回答
1

Each of the commas in your $.post() function assign that value to different arguments. In order to pass all of those values, at once, you'll want to use one object:

function finish() {
  var cnt1 = 50;
  var tim = 60;
  var hecho = 1;

  $.post("index.php", { t:tim, m:cnt1, e:hecho } );
}
于 2013-04-17T23:19:39.077 回答