PHP没有拿起Ajax POST

I'm trying to send some data from a HTML page to a PHP page.

I've made sure that the dataString is actually sending text by using console log.

It shows up as pid=12345

My AJAX is:

$.ajax({
  type: "POST",
  url: 'Task2.php',
    data: {pid:res[1]},
  success: function(data) {
    //alert(data);
      $("#container").html(data); 
      console.log( data );
 }
});

My PHP is:

$temp = $_POST['pid'];

The PHP isn't picking it up even if I do it manually by going to myserver/Task2.php?pid=12345.

I think you may be looking for something like this...

var dataString = res[1];
console.log( 'pid=' + dataString );

$.ajax({
  type: "POST",
  url: 'Task2.php',
  data: { pid: dataString },
  success: function(data) {
    alert(data);
  }
});

by specifying data: { pid:dataString } in your ajax call, your telling it to POST the dataString value as a form element named "pid". You chould be able to pick it up PHP side with $_POST['pid'];

EDIT

Here is a full, working example. All self contained in a single PHP file. Should help you get it sorted out. The reason for the isset($_GET['testing']) at the top is because I'm using the same file in the ajax call too. Just fyi...

<?php
    if (isset($_GET['testing'])) {
        if (isset($_POST['pid'])) {
            echo $_POST['pid'];
        } else {
            echo 'not set';
        }
    }
    else
    {
?>
<html>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<a href="javascript:void(0);" onclick="test()">test</a>
<script type="text/javascript">
    function test() {
        var dataString = "pid=testing123";
        $.ajax({
            type: "POST",
            url: "test.php?testing",
            data: dataString,
            success: function(result) {
                alert(result);
            }
        });
    }
</script>
</html>
<?php
    }
    ?>
var data = {pid: res[1]}

$.ajax({
  type: "POST",
  url: 'Task2.php',
    data: data,
  success: function(data) {
    alert(data);
  }
});

You cannot read from $_POST When using $_GET params (?pid=12345)

Data should be a hash:

$.ajax({
  type: "POST",
  url: 'Task2.php',
    data: {pid:res[1]},,
  success: function(data) {
    alert(data);
  }
});

And in php don't mix $_GET with $_POST. http://example.com/a.php?q=1 => $_GET['q'], but the above ajax code will send it to $_POST['pid']