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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵