WEB开发网
开发学院网页设计JavaScript 创建面向对象的Javascript实现Ajax访问QQ留言板 阅读

创建面向对象的Javascript实现Ajax访问QQ留言板

 2009-09-28 00:00:00 来源:WEB开发网   
核心提示: 然后创建具体的获取分析QQ空间留言板信息的模块qq.modules.LeaveMessage.js/**Description:QQ空间留言板获取信息模块*Author:Sonven*Create:2009-09-27*Modify:2009-09-27***/functionQQLeaveMe

然后创建具体的获取分析QQ空间留言板信息的模块

qq.modules.LeaveMessage.js

/*************************
* Description  :    QQ空间留言板获取信息模块
* Author     :    Sonven
* Create     :    2009-09-27
* Modify     :    2009-09-27
***************************/
function QQLeaveMessage(qq, pageIndex,pageSize) {
    this.qq = qq;
    pageIndex = pageIndex == null || pageIndex < 1 ? 1 : pageIndex;   //当前页数
    pageSize = pageSize == null || pageSize < 0 ? 10 : pageSize;     //每页大小
    this.start = (pageIndex - 1) * pageSize;                       //获取开始条数
    if (this.start == 0) this.start = 1;
    this.num = pageSize;                                        //获取每页数量
    //MessageCountInfo
    this.totalNum = 0;
    this.currentDisplayNum = 0;
    this.title = qq + "的留言板";
    this.description = null;
    this.authorsign = null;
    this.messageContent = null;
}
QQLeaveMessage.prototype.receive = function(callback) {
    var returnMsg = "查询不到你的留言信息!";
    var requestUri = "http://m.qzone.qq.com/cgi-bin/new/msgb_page.cgi?uin=" + this.qq + "&archive=0&start=" + this.start + "&num=" + this.num;
    requestUri = "x.xml";  //这里替换了数据地址为本地文件,实际操做应该删除此行
    var s = new XMLHttpRequestObject("GET", "XML", requestUri, {});
    s.request(function(x) {
        //此时返回的对象与XMLHttpRequestObject的返回类型一致
        var channel = x.getElementsByTagName("channel")[0];
        this.totalNum = channel.getAttribute("totalNum");        //共有条数
        this.title = channel.childNodes[0].text;                //标题
        this.description = channel.childNodes[1].text;            //Description
        this.authorsign = channel.childNodes[2].text;            //Authorsign
        var msgNodes = channel.getElementsByTagName("item");
        this.currentDisplayNum = msgNodes.length;             //Current Display Num
        var msgHtml = "";                              //Temp message html
        var c = null;                                  //Temp child node
        var cs = null;                                 //Temp child node's comment nodes
        var scs = null;                                //one of temp child node's comment nodes
        var authorID;                                  //The id of leave message author
        var authorName;                               //The name of leave message author
        for (var i = 0; i < msgNodes.length; i++) {
            c = msgNodes[i];
            authorID = c.getAttribute("uin");
            authorName = c.getElementsByTagName("author")[0].text;
            msgHtml += "<li><div class='msgTop'>第" + (i + 1) + "条,留言编号:" + c.getAttribute("answerid") + "发表于:" +
                c.getElementsByTagName("pubDate")[0].text + "</div><div class='msgTitle'>" +
                authorName + "[" + authorID + "]<br/>" +
                "<span class='title'>" + c.getElementsByTagName("title")[0].text + "</span></div>";
            //分析回复信息
            cs = c.getElementsByTagName("comment");
            for (var j = 0; j < cs.length; j++) {
                scs = cs[j];
                msgHtml += "<div class='msgComment'>" +
                (scs.getAttribute("uin") == authorID ? authorName : "空间主人回复:") +
                scs.text+"</div>";
            }
            msgHtml += "</li>";
        }
        this.messageContent = "<ul>" + msgHtml + "</ul>";                    //return message items html
        callback(this); //调用回调函数
    });
}

上一页  1 2 3 4  下一页

Tags:创建 面向 对象

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接