黑马程序员技术交流社区

标题: 求整个网站实现ajax [打印本页]

作者: 杨志罡    时间: 2011-7-23 02:07
标题: 求整个网站实现ajax
求整个网站实现ajax,省掉众多马友守着电脑用鼠标刷新页面
作者: 匿名    时间: 2011-7-24 16:49
[code=jscript]$(function() {
                //$.cookie("user",null);
                 var user =$.cookie("user");
                if(user !=null){
                        $("#loginDiv").html("");
                                        $("#loginDiv").append("<table align='center'><tr><td width=''><font color='red'>当前用户:        "+user+"</font></td></tr><tr><td width='150'><a href='my.htm' >管理我的租房信息</a></td></tr>        <tr><td width='100'><a href='post.htm' id='releaseZfxx'>发布租房信息</a></td></tr><tr><td width='100'><a href='#' id='cancellation'>[注销]</a></td></tr></table>")
                        $("#releaseZfxx").click(function(){
                                $.cookie("fwxx",null);
                        })
                        $("#cancellation").click(function(){
                                $.cookie("user",null);
                                $.cookie("uid",null);
                                location.href = "index.html";
                        })
                }
                        $.ajax( {
                                url : "zfxx.action",// 定义提交的url
                                dataType : 'json', // 定义返回的类型为json
                                type : 'post', // 定义提交的方式为post
                                beforSend:function(){
                                                $("#zfxx").append( "<tr><td width='250'>数据请求中,清稍后...</td></tr>")
                                },
                                error : function(xhr) {
                                        alert('error\n\n' + xhr.responseText);
                                },
                                success : function(data) {// 正常返回数据时执行的函数
                                        // 以下是返回的user实体类
                                // alert(data.list.zfxx.tible);
                                $("#zfxx").html("");
                                if (data.list != undefined)
                                        for (i = 0; i < data.list.length; i++) {
                                                ///alert(data.list[i].title);
                                                $("#zfxx").append( "<tr><td width='150'><a href='detail.htm' class='showDetail' title='"+data.list[i].fwid+"'>"+ data.list[i].title+ "</a></td><td width='200' align='center'  class='table_title'>"+ data.list[i].zj+ "</td><td align='center'>"        + data.list[i].date        + "</td></tr>")
                                        }       
                                        $(".showDetail").click(function(){
                                                $.cookie("zfxxId",null);
                                                $.cookie("zfxxId",this.title)
                                        })
                        }
                })
                $.ajax( {
                        url : "getQx.action",
                        type : "post",
                        dataType : "json",
                        error : function(xhr) {
                                alert('error\n\n' + xhr.responseText);
                                //alert(window.location.href);
                        },
                        success : function(data) {
                                for (i = 0; i < data.list.length; i++) {
                                                //alert(data.list[i].qx);
                                                 $("<option value='"+data.list[i].qxid+"'>"+data.list[i].qx+"</option>").appendTo($(".qx"));
                                }       
                                $(".qx").change(function(){
                                        //alert($(".qx").val());
                                        $.ajax( {
                                                url : "findQx.action",
                                                type : "post",
                                                dataType : "json",
                                                data : "qxid=" + $(".qx").val(),
                                                error : function(xhr) {
                                                        alert('error\n\n' + xhr.responseText);
                                                        //alert(window.location.href);
                                                },
                                                success : function(data) {
                                                        //alert(data.qx.jds.length);       
                                                        $(".jd").html("");
                                                        $("<option value='0'>不限--</option>").appendTo($(".jd"));
                                                        for (i = 0; i < data.qx.jds.length; i++) {
                                                                 $("<option value='"+data.qx.jds[i].jdid+"'>"+data.qx.jds[i].jd+"</option>").appendTo($(".jd"));
                                                        }
                                                }
                                        });
                                })
                        }
                })
})[/code][code=jscript]$(function() {
        $("#loginDiv").html("");
        $("#loginDiv")
                        .append(
                                        "<table align='center'><tr><td width=''><font color='red'>当前用户:        "
                                                        + $.cookie("user")
                                                        + "</font></td></tr><tr><td width='150'><a href='my.htm' id='myZfxx'>管理我的租房信息</a></td></tr>        <tr><td width='100'><a href='#' id='releaseZfxx'>发布租房信息</a></td></tr><tr><td width='100'><a href='#' id='cancellation'>[注销]</a></td></tr></table>")
                $("#releaseZfxx").click(function(){
                        $.cookie("fwxx",null);
                        $.cookie("updateByzfxxId",null);
                        location.href ="post.htm";
                })
                $("#cancellation").click(function(){
                        $.cookie("user",null);
                        $.cookie("uid",null);
                        location.href = "index.html";
                })
        $.ajax( {
                                url : "myZfxx.action",
                                type : "post",
                                dataType : "json",
                                data : "uid=" + $.cookie("uid"),
                                error : function(xhr) {
                                        alert('error\n\n' + xhr.responseText);
                                },
                                success : function(data) {
                                        //$("#zfxx").html("");
                                        //alert(data.list.length);
                                        for (i = 0; i < data.list.length; i++) {
                                                // alert(data.user1.zfxxes[i].date);
                                                $("#zfxx").append("<tr><td><a class ='showDetail' title='"+data.list[i].fwid+"' href='detail.htm'>"+data.list[i].title+"</a></td>        <td align='center' style='height:30px;'>"+data.list[i].zj+"元</td><td align='center' style='height:30px;'>"+data.list[i].date+"</td><td align='center' style='height:30px;'><a href='#' class='del' title='"+data.list[i].fwid+"'>[删除]</a></td><td align='center' style='height:30px;'><a href='#' class='update' title='"+data.list[i].fwid+"'>[修改]</a></td></tr>");
                                                $("#zfxx").append("<tr>        <td colspan='5'><hr /></td></tr>")
                                        }
                                        $(".showDetail").click(function(){
                                                $.cookie("zfxxId",null);
                                                $.cookie("zfxxId",this.title)
                                                //alert(this.title);
                                        })
                                        $(".del").click(function(){
                                                var id = this.title;
                                                if(confirm("确实要删除吗?")){
                                              $.ajax( {
                                                                url : "delZfxx.action",
                                                                type : "post",
                                                                dataType : "json",
                                                                data : "id=" + id,
                                                                error : function(xhr) {
                                                                        alert('error\n\n' + xhr.responseText);
                                                                        alert( window.location.href);
                                                                },
                                                                success : function(data) {
                                                                        alert("删除成功!");       
                                                                        location.href ="my.htm";
                                                                }               
                                                        })
                                           }else{
                                                  alert("已经取消了删除操作");
                                           }
                                        })
                                        $(".update").click(function(){
                                                var id = this.title;
                                                $.cookie("fwxx",null);
                                                $.cookie("fwxx",this.title)
                                                $.cookie("updateByzfxxId",null)
                                                $.cookie("updateByzfxxId",this.title)
                                                //alert($.cookie("updateByzfxxId"));
                                                location.href ="post.htm";
                                        })
                                }
                });
})[/code][code=jscript]$(function() {
        $("#loginDiv").html("");
        $("#loginDiv")
                        .append(
                                        "<table align='center'><tr><td width=''><font color='red'>当前用户:        "
                                                        + $.cookie("user")
                                                        + "</font></td></tr><tr><td width='150'><a href='my.htm' id='myZfxx'>管理我的租房信息</a></td></tr>        <tr><td width='100'><a href='post.htm' id='releaseZfxx'>发布租房信息</a></td></tr><tr><td width='100'><a href='#' id='cancellation'>[注销]</a></td></tr></table>")
        $("#cancellation").click(function(){
                $.cookie("user",null);
                $.cookie("uid",null);
                location.href = "index.html";
        })
        $.ajax( {
                                url : "getZfxx.action",
                                type : "post",
                                dataType : "json",
                                data : "id=" + $.cookie("zfxxId"),
                                error : function(xhr) {
                                        alert('error\n\n' + xhr.responseText);
                                        //alert( window.location.href);
                                },
                                success : function(data) {
                                        //alert(data);
                                        $("#zfxx").append("<tr>        <td id=listTitle>"+data.zfxx.title+"</td></tr><tr><td id=listTitle><hr/></td></tr><tr><td><strong>电话/手机:</strong>"+data.zfxx.telephone+"</td> </tr><tr><td><strong>联系人:</strong>"+data.zfxx.lxr+"</td></tr><tr><td><strong>房屋类型:</strong>"+data.zfxx.fwlx.fwlx+"</td></tr><tr>                <td><strong>户型:</strong>"+data.zfxx.shi+"室"+data.zfxx.ting+"厅</td></tr><tr><td><strong>价格:"+data.zfxx.zj+"</strong>元</td></tr><tr><td><strong>地段:</strong>"+data.zfxx.qx.qx+"&nbsp;&nbsp;"+data.zfxx.jd.jd+"</td></tr><tr><td><strong>发布时间:</strong> "+data.zfxx.date+"</td></tr><tr><td><hr></td></tr><tr><td >"+data.zfxx.fwxx+"</td></tr><tr><td><input type='button' value='后退' class='btn' onClick='back()'></td></tr>")
                                }
                });
})[/code]有点乱,这是我写的期末作业的一部分,jquery adjx。
作者: 匿名    时间: 2011-7-24 17:02
看得出楼上是个牛学员!!!期待请教




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2