0

I would like to add an id value from html to php. This is my script:

HTML CODE:

<body>
<script type="text/javascript" src="jquery/jquery.min.js"></script>
<script>

   xy.on("click", function() {
     window.location = "/pieplots/pie.php";  
     var id=100;        //HOW CAN I ADD THIS VELUE, TO THE OPENED pie.php?
   });

PHP CODE:

<?php // content="text/plain; charset=utf-8"

$id = $_POST['id'];
echo $id;

Thanks for your help

4
  • is it a post request or a get request Commented Mar 21, 2013 at 12:13
  • do you want a ajax loading Commented Mar 21, 2013 at 12:14
  • if you want to use GET, then you can simply attach id=100 after the url, for example: "/pieplots/pie.php?id=" + id Commented Mar 21, 2013 at 12:14
  • why dont you include the variable in the window location and retrieve it with $_GET? Commented Mar 21, 2013 at 12:14

4 Answers 4

2

Becouse you use post params, you should make a post:

$.ajax({
 type: "POST",
 url:"/pieplots/pie.php",
 data: { id: 100 }
})

Üdv, Bálint

Sign up to request clarification or add additional context in comments.

Comments

1

If it is not mandatory to use POST, try this code in script:

 xy.on("click", function() {
var id=100;
 window.location = "/pieplots/pie.php?id=" + id;             
});`

and this one in php:
$id = $_GET['id']; echo $id;

Comments

0
xy.on("click", function() {
     var id=100;        //HOW CAN I ADD THIS VELUE, TO THE OPENED pie.php?
     window.location = "/pieplots/pie.php?id=" + id;  
});

server side may have to be changes as below since you are sending a GET request

$id = $_GET['id'];

Comments

0

If you want the browser to make a post request (not ajax) you will have to have a <form> for that. Something like this could work:

xy.on('click', function(){
    var id = 100;
    $('<form method="post" action="/pieplots/pie.php">'+
      '<input type="hidden" name="id" value="'+id+'">'+
      '</form>').appendTo($('body')).submit();
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.