开发者

Passing variables from Jquery to PHP

I have tried everythinng anmad cannot get this prograam to work. This is a chess program. When a user double clicks on a square on the board, the cell should be added to the form in the move_to/move_from variable.

Here are code snippits:

<?php
 $results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn", "Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"),
            array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),
            array("", "", "", "", "", "", "", ""),array("Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"),
            array("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", "Wn", "Wr"));

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


    <head>
        <title>Jquery Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" href="jq.css" rel="stylesheet" />
        <link type="text/css" href="jquery-ui-1.8.9.custom.css" rel="stylesheet" />
    </head>
<!-- Uses Session Variables -->
        <body>
            <div id="main">
            <fieldset  id="main_fieldset">
                <table  cellspacing="100">
                    <tbody >
                        <tr>
                            <td class="b1">8</td><td class="d1" id="a8"><?php echo $results[0][0];?> </td><td class="a1" id="b8" ><?php echo $results[0][1];?>  
                                </td><td class="d1" id="c8"> <?php echo $results[0][2];?> </td><td class="a1" id="d8"> 
                                <?php echo $results[0][3];?> </td><td class="d1" id="e8"><?php echo $results[0][4];?>  </td><td class="a1" id="f8"> 
                                <?php echo $results[0][5];?> </td>
                                <td class="d1" id="g8"> <?php echo $results[0][6];?> </td><td class="a1" id="h8"> <?php echo $results[0][7];?>  </td>
                        </tr>

snip..

<script type="text/开发者_C百科javascript">
$(document).ready(function(){
        $('.a1').click(function() {
            $(this).css("background-color","grey");
        });
}); 
</script>

<script type="text/javascript">
$(document).ready(function(){
        $('.a1').dblclick(function() {
            $(this).css("background-color","blue");
            move_from = $(this).attr("id");
            $.post('jq_test.php',move_from);
            alert(move_from);
    });
});

    <p><a href="jq_test.php?move_from">x</a></p>

<?php 
                    echo "this is the variable   ";echo $_GET['move_from'];
                    print_r($_GET);
?>

snip...

<?php       
    echo <<<HTML
            <form method="post" action="jq_test.php">
            Move From<input type="text" name="move_from"> </input><br /><br />
            Move To  <input type="text" name="move_to"></input><br /><br />
                <input type="submit" value="Enter Move"></input>

            </form>
    HTML;
?>

    </body>

</html> 


Your javascript is using $.post(), but you're retrieving from $_GET in PHP. Switch to $_POST in PHP instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜