weixin_33691700 2014-05-25 13:28 采纳率: 0%
浏览 24

多个变量ajax到PHP [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/8898108/php-logical-operators-precedence-affects-variable-assignment-results-strangely" dir="ltr">PHP Logical Operators precedence affects variable assignment results strangely</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2014-05-25 13:41:48Z" class="relativetime">5 years ago</span>.</div>
        </div>
    </aside>

Plain and simple, this is what I am trying to create:

function addComment($post_id, $user_id, $comment) {
    var post_id = $post_id;
    var user_id = $user_id;
    var comment = $comment;

    var xhr;
    if (window.XMLHttpRequest) xhr = new XMLHttpRequest();
    else xhr = new ActiveObject("Microsoft.XMLHTTP");

    var url = 'commentcreate.php?post_id=' + post_id + '&user_id=' + user_id + '&comment=' + comment
    xhr.open('GET', url, false);
    xhr.onreadystatechange = function () {
    if (xhr.readyState===4 && xhr.status===200) {
            div.innerHTML = xhr.responseText;           
        }
    }
    xhr.send();
    return false;

And then I got the PHP file which would be recieving these variables:

if(isset($_GET['post_id']) && isset($_GET['user_id']) && isset($_GET['comment'])) $post_id = $_GET['post_id'] && $user_id = $_GET['user_id'] && $comment = $_GET['comment'];

Which is code that is extremely hard to read that is meant as working like the following:

if (
    isset($_GET['post_id'])
    && isset($_GET['user_id'])
    && isset($_GET['comment'])
) {
    $post_id = $_GET['post_id'];
    $user_id = $_GET['user_id'];
    $comment = $_GET['comment'];
}

So basicly, I want a function that takes 3 variables, and sends them over to a php file where I can do my thing and add them to the database (to create a comment). But this does not work. It works with 1 variable, but I dont know how to get it to work with more then 1. Im guessing that its something wrong on the php side, but i could be wrong. Any suggestions?

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33694620 2014-05-25 13:33
    关注

    try changing

    if(isset($_GET['post_id']) && isset($_GET['user_id']) && isset($_GET['comment']))  
       $post_id = $_GET['post_id'] && 
       $user_id = $_GET['user_id'] && 
       $comment = $_GET['comment'];
    

    to

    if(isset($_GET['post_id']) && isset($_GET['user_id']) && isset($_GET['comment'])) {
       $post_id = $_GET['post_id'];
       $user_id = $_GET['user_id']; 
       $comment = $_GET['comment'];
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响