tags:

views:

31

answers:

1

hi i have problem in jquery and php, i am posting data through $.post in jquery but not enable to get data in the next page please healp

jquery code

<?php
    include 'dbconnect.php';
    $query=mysql_query("select * from test");
?>
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
    $(function(){
        $("button").click(function(){
            var aid = $(this).attr("id");
            var value=$("#id"+aid).val();
            value++;
            $("#id"+aid).val(value);
            var val= $("#id"+aid).val();
            $.post("test_sub.php", {id:"aid", name: "val"}, function(){
                alert(aid);
            });
        });
    });
</script>
</head>
<body>
<?
    $i=0;
    while($res=mysql_fetch_row($query))
    {
        $i++;
        $point=$res[1];
        $id=$res[0];
?>
<tr>
<td>
<input type="text" id="id<?=$id?>" name="user" value="<? echo $point; ?>" />
<button id="<?=$id?>" class="button">Change value for the text field</button>
</td>
</tr>

</body>

<?
    }
?>
</body>
</html>

php code

<?php
    include 'dbconnect.php';
    $id  = $_POST['id'];  
    $name  = $_POST['name']; 
    $sql="update test set name='fdf' where id=$id";
    $query=mysql_query($sql) or die(mysql_error());
?>

in this page i am not getting the value of $_post['id'] and $_post['name'] if anybody have solution please help me

A: 

Hmm... Try to declare you js event just like:

$("button").click(function(){
    var aid = $(this).attr("id");
    var value=$("#id"+aid).val();
    value++;
    $("#id"+aid).val(value);
    var val= $("#id"+aid).val();
    $.post("test_sub.php", {id:"aid", name: "val"}, function(){
        alert(aid);
    });
});
Saff