0

I need to get to another page and post some data. I want to post Javascript variable from "index.php" and get PHP variable on "zakazka.php". I need to start the function with click on span text, so I don't want to use form.

I had found that redirect will help me, but can't make a simple example work -

Index.php:

<html>
 <head>
  <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
 </head>
<body>

<?php
session_start();
$user="abc";
$_SESSION["user"] = $user;
?>

<span id="1" onclick="get()">hello</span>
</body>
</html>

<script>
function get()
  {
  kod="1";
  $.redirect('zakazka.php', {'kodsend': kod});  
  }
</script>

Zakazka.php:

<?php
session_start();
$user=$_SESSION['user'];
$kodr = $_POST['kodsend'];

echo $kodr;
?>
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
Olda Stiller
  • 65
  • 1
  • 9
  • 1
    *"it do nothing"* ... actually it does, it throws an error in your browser console. You haven't included any definition for `$.redirect`. Also you can't post this way...would be `$_GET['kodsend']` – charlietfl Apr 16 '17 at 12:21

1 Answers1

0

This method isn't native to jQuery. I assume it's this plugin, although you don't mention it: https://github.com/mgalante/jquery.redirect.

If so, you need to include something like

<script src="path/to/jquery.redirect.js"></script>

in your page, having ensured you downloaded the plugin file to the correct folder in your website.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Thank you for answer... redirect didnt help me, later i solved this problem this way http://stackoverflow.com/questions/8191124/send-javascript-variable-to-php-variable – Olda Stiller Apr 18 '17 at 20:45