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 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64