douge3113 2011-12-01 19:41
浏览 37

AJAX / PHP问题

I'm updating a messaging system on my website, and I can't figure out why the following chunk of code isn't working At All:

function sendReply(id,from,to)
{
    var subject = document.getElementById("subject").innerHTML;
    var body = document.getElementById("body").innerHTML;
    var xmlhttp;
    if (id.length==0) {
        document.getElementById("userMessagingBackground").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", "sendOutReply.php?from=" + from + "&to=" + to + "&subject=" + subject + "&body=" + body, true);
    xmlhttp.send();
    document.getElementById("userMessagingBackground").style.display = "none";
}

So...Uh...Is there anything wrong with this? If not...Here's the PHP part:

<?php
    $to = $_GET['to'];
    $dbc = mysqli_connect(Database Connection Stuff);
    $username = $_GET['user'];
    if (!empty($_GET['body'])) {
        $sub = $_GET['subject'];
        $body = "Sent by $username:
---
" 
            . $_GET['body'] . "

------------------------

"
            . $receivedMsg;
        $STM = "INSERT INTO messagingTable 
            (new, sender, receiver, subject, message, sentDate) 
            VALUES ('1', '$username', '$to', 'RE: $subject', '$body', NOW())";
        $sendMessage = mysqli_query($dbc, $STM);

        $findReceiver = "SELECT * FROM usersTable WHERE username = '$to'";
        $getTo = mysqli_query($dbc,$findReceiver);
        $toRow = mysqli_fetch_array($getTo);

        if ($toRow['emailOnPm'] == 1) {
            mail($toRow['email'],$sub,$body, "From: AllThemGames.com");
        }
    }
?>
  • 写回答

3条回答 默认 最新

  • dstm2014 2011-12-01 19:50
    关注

    Your Ajax call function is missing a callback function. For example:

    xmlHttp.onreadystatechange = function(){
        if(this.readyState == 4)
            //Do you call back
    )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错