【问题标题】:Loading a page in another page via Ajax通过 Ajax 在另一个页面中加载页面
【发布时间】:2014-04-25 15:53:39
【问题描述】:

我在 PHP 页面中进行了 Ajax 聊天,一切都运行良好且流畅。 然后我尝试在弹出的 div 中的另一个页面上采用此聊天(通过 z-index 上的 css)。

这是代码:

function showChat(username){
                    var
                        $http,
                        $self = arguments.callee;

                    if (window.XMLHttpRequest) {
                        $http = new XMLHttpRequest();
                    } else if (window.ActiveXObject) {
                        try {
                            $http = new ActiveXObject('Msxml2.XMLHTTP');
                        } catch(e) {
                            $http = new ActiveXObject('Microsoft.XMLHTTP');
                        }
                    }

                    if ($http) {
                        $http.onreadystatechange = function()
                        {
                            if (/4|^complete$/.test($http.readyState)) {
                                window.parent.document.getElementById('chatbox').style.display = "block";
                                window.parent.document.getElementById('chatbox').innerHTML = $http.responseText;
                            }
                        };
                        $http.open('GET', "dashchat/chatbox.php?chatWith="+username, true);
                        $http.send(null);
                    }
        }

div 显示,聊天的文本框显示,但消息不显示 ajax 没有运行,当我提交消息时它重定向到我的 sendmessage.php 有什么想法吗?

【问题讨论】:

  • 你得到了什么回应?
  • 我正在获取我的 php 页面,但 ajax 没有运行
  • 但是如果我去那个聊天页面本身就可以正常工作

标签: javascript php jquery ajax


【解决方案1】:

试试这个

function showChat(username) {
    var 
                        $http,
                        $self = arguments.callee;

    if (window.XMLHttpRequest) {
        $http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            $http = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e) {
            $http = new ActiveXObject('Microsoft.XMLHTTP');
        }
    }

    if ($http) {
        $http.onreadystatechange = function () {
            if ($http.readyState == 4) {
                window.parent.document.getElementById('chatbox').style.display = "block";
                window.parent.document.getElementById('chatbox').innerHTML = $http.responseText;
            }
        };
        $http.open('GET', "dashchat/chatbox.php?chatWith=" + username, true);
        $http.send(null);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-16
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多