开发者

problem to post data in jquery to a php page

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(){
        $("bu开发者_JAVA百科tton").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


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);
    });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜