dqy006150 2013-07-24 13:28
浏览 37

如何在某些PHP代码中使用jQuery var?

I know there are a few topics on this subject, but after I spent 2 or 3 hours trying to get something good out of them, I just decided to ask this question on a specific point.

So here is my problem : I have got a table and I am using a jQuery function to select a row of this table. Now what i actually want to do is getting the text content of the div contained in the first td of the row.

I already used a getter on it and I am checking the getted value with an alert as you can see in th following code :

    $("#myRow").click(function() {
        $(".selectedRow").removeClass("selectedRow").addClass("unselected");
        $(this).addClass("selectedRow").removeClass("unselected");
        var myValue = $(".selectedRow .firstTd div").text();
        alert('myValue');
    });

So now, what I am trying to do is to send the myValue variable through an ajax request by replacing my alert by this piece of code :

    $.ajax({
        type: 'get',
        url: 'index.php',
        data: {"myValue" : myValue},
        success: function(rs)
        {
            alert(myValue);
        }
    });

Then, back to my php code, I am tring to observe the obtained variable by using an echo, just like this :

    <?php echo $_GET['myValue']; ?>

But there is just no way for me to know if my page got it beacause the echo just prints nothing... So i was wondering if someone could do something for me. Thanks.

PS : Oh, by the way ; I don't really know if this can matter, but my page index.php already receives data by a post.

  • 写回答

5条回答 默认 最新

  • dongnao6858 2013-07-24 13:32
    关注

    Do a var dump of the request var to see if anything is coming through:

    <?php
    var_dump($_REQUEST);
    

    If not, do a console.log() on 'myValue' to make sure it exists before sending the ajax request - the issue may lie in your js rather than you php.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错