XML保存 跪求大神帮忙解决 最好有代码

解决方案 »

  1.   

    每次页面被载入的时候就$.post下后台处理页面然后相关数据库的点击率加1就行了吧,具体的还有其他办法,根据lz兴趣爱好决定吧
      

  2.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
      

  3.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
    这个代码放在aspx文件中的么,我是静态页 没有啊
      

  4.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
    这个代码放在aspx文件中的么,我是静态页 没有啊
    这个 写个 方法
    html 页 通过ajax 来调用这个方法啊
      

  5.   

    XML保存到客户端?这不一定行,放到服务端,可以通过ajax提交,存数据库或者其他比XML更好的形式
      

  6.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
    这个代码放在aspx文件中的么,我是静态页 没有啊
    我是把点击量存到了XML中 用JS实现点击刷新..但是不知道怎么用JS调用XML文件
      

  7.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
    这个代码放在aspx文件中的么,我是静态页 没有啊
    我是把点击量存到了XML中 用JS实现点击刷新..但是不知道怎么用JS调用XML文件
    你点击量就一个数字 非得存在xml结构中吗?
    把上边的代码 写到一个 web 服务页面
    html页面通过ajax  访问这个服务页面
    你js 不能直接修改服务器的xml 啊
      

  8.   

    refer : http://zhidao.baidu.com/question/96919828.html
      

  9.   

    只是 点击数  用txt 就好了。StreamReader fread = new StreamReader(Server.MapPath("count.txt"), System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";     
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(Server.MapPath("count.txt"), false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
    这个代码放在aspx文件中的么,我是静态页 没有啊
    我是把点击量存到了XML中 用JS实现点击刷新..但是不知道怎么用JS调用XML文件
    你点击量就一个数字 非得存在xml结构中吗?
    把上边的代码 写到一个 web 服务页面
    html页面通过ajax  访问这个服务页面
    你js 不能直接修改服务器的xml 啊兄弟 你能告诉我Web服务页面到底是哪个..我蒙了 
      

  10.   

    新建服务页面  CountHandler.ashx
    <%@ WebHandler Language="C#" Class="CountHandler" %>using System;
    using System.Web;
    using System.IO;
    public class CountHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string countFile=context.Server.MapPath("count.txt");//存放总访问量文件
            StreamReader fread = new StreamReader(countFile, System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(countFile, false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
            context.Response.Write("success");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}静态页面访问服务页面更新点击量(基于jquery.js)$(function () {
            $.post('CountHandler.ashx', function (data, status) { });
        }); 
      

  11.   

    新建服务页面  CountHandler.ashx
    <%@ WebHandler Language="C#" Class="CountHandler" %>using System;
    using System.Web;
    using System.IO;
    public class CountHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string countFile=context.Server.MapPath("count.txt");//存放总访问量文件
            StreamReader fread = new StreamReader(countFile, System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(countFile, false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
            context.Response.Write("success");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}静态页面访问服务页面更新点击量(基于jquery.js)$(function () {
            $.post('CountHandler.ashx', function (data, status) { });
        }); 

    这个是更新的对把  但是我还是想把XML里的点击量弄出来..不管怎么样 都很谢谢你了。 分怎么给你啊。我不会 告诉我
      

  12.   

    新建服务页面  CountHandler.ashx
    <%@ WebHandler Language="C#" Class="CountHandler" %>using System;
    using System.Web;
    using System.IO;
    public class CountHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string countFile=context.Server.MapPath("count.txt");//存放总访问量文件
            StreamReader fread = new StreamReader(countFile, System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(countFile, false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
            context.Response.Write("success");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}静态页面访问服务页面更新点击量(基于jquery.js)$(function () {
            $.post('CountHandler.ashx', function (data, status) { });
        }); 

    这个是更新的对把  但是我还是想把XML里的点击量弄出来..不管怎么样 都很谢谢你了。 分怎么给你啊。我不会 告诉我
    那就把 CountHandler.ashx  中更改txt的代码 改成 更改xml文件的
    结贴 就可以了
      

  13.   

    用js来统计无法保存,保存为xml文件的话在本地无意义,并且浏览器安全等设置,不太容易成功,唯一可行的就是ajax到后台
      

  14.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
      

  15.   

    新建服务页面  CountHandler.ashx
    <%@ WebHandler Language="C#" Class="CountHandler" %>using System;
    using System.Web;
    using System.IO;
    public class CountHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string countFile=context.Server.MapPath("count.txt");//存放总访问量文件
            StreamReader fread = new StreamReader(countFile, System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(countFile, false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
            context.Response.Write("success");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}静态页面访问服务页面更新点击量(基于jquery.js)$(function () {
            $.post('CountHandler.ashx', function (data, status) { });
        }); 

    这个是更新的对把  但是我还是想把XML里的点击量弄出来..不管怎么样 都很谢谢你了。 分怎么给你啊。我不会 告诉我
    那就把 CountHandler.ashx  中更改txt的代码 改成 更改xml文件的
    结贴 就可以了

    把你QQ告诉我把 以后多请教请教你
      

  16.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
    关键是怎么写啊 给点代码..我就是静态页实现一个浏览次数 这么费劲呢么
      

  17.   

    纯静态页面  没可能
    最简单的  必须后台写计数器  用ajax返回给页面
      

  18.   

    新建服务页面  CountHandler.ashx
    <%@ WebHandler Language="C#" Class="CountHandler" %>using System;
    using System.Web;
    using System.IO;
    public class CountHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string countFile=context.Server.MapPath("count.txt");//存放总访问量文件
            StreamReader fread = new StreamReader(countFile, System.Text.Encoding.Default);
            string oldString = fread.ReadToEnd().Trim();
            string newString = "0";
            fread.Close();
            fread.Dispose();
            if (!string.IsNullOrEmpty(oldString))
            {
                newString = (Convert.ToInt64(oldString) + 1).ToString();
            }
            StreamWriter sw = new StreamWriter(countFile, false, System.Text.Encoding.Default);
            sw.Write(newString);
            sw.Close();
            sw.Dispose();
            context.Response.Write("success");
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}静态页面访问服务页面更新点击量(基于jquery.js)$(function () {
            $.post('CountHandler.ashx', function (data, status) { });
        }); 
    现在我想用数据库更新点击量 怎么弄呢。 多个新闻标题 点其中一个只更新这个 不是所有点击量都更新
      

  19.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
    关键是怎么写啊 给点代码..我就是静态页实现一个浏览次数 这么费劲呢么
    你是想 点击新闻标题时候更新点击量?
    一般是 在点击新闻进入新闻内容页后 更新点击量
    你的新闻 内容页是 静态页 还是  动态页?
      

  20.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
    关键是怎么写啊 给点代码..我就是静态页实现一个浏览次数 这么费劲呢么
    你是想 点击新闻标题时候更新点击量?
    一般是 在点击新闻进入新闻内容页后 更新点击量
    你的新闻 内容页是 静态页 还是  动态页?
    如你所说 就是点击新闻标题的时候更新点击量 从数据库中提取新闻的标题然后更新
    静态页面。
      

  21.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
    关键是怎么写啊 给点代码..我就是静态页实现一个浏览次数 这么费劲呢么
    你是想 点击新闻标题时候更新点击量?
    一般是 在点击新闻进入新闻内容页后 更新点击量
    你的新闻 内容页是 静态页 还是  动态页?
    如你所说 就是点击新闻标题的时候更新点击量 从数据库中提取新闻的标题然后更新
    静态页面。

    不知楼主 为什么要点击标题的时候更新点击量啊?
    要是从搜索引擎 直接进入内容页的 不算点击量?
    如果 点标题就更新 那 你所有的列表页 还有 首页 等等 有标题的都要 加上更新点击量方法?
      

  22.   


    如楼上所说,后台需要一个ashx的文件来接收ajax请求,并将传送的数据保存起来
    关键是怎么写啊 给点代码..我就是静态页实现一个浏览次数 这么费劲呢么
    你是想 点击新闻标题时候更新点击量?
    一般是 在点击新闻进入新闻内容页后 更新点击量
    你的新闻 内容页是 静态页 还是  动态页?
    如你所说 就是点击新闻标题的时候更新点击量 从数据库中提取新闻的标题然后更新
    静态页面。

    不知楼主 为什么要点击标题的时候更新点击量啊?
    要是从搜索引擎 直接进入内容页的 不算点击量?
    如果 点标题就更新 那 你所有的列表页 还有 首页 等等 有标题的都要 加上更新点击量方法?
    大哥呀 你就救救我把 我这是刚实习 给了我一个小项目 让我整。到这就卡住一点不会了。
    加我QQ你详细的告诉我好不好 啥报酬都OK.2451424108
      

  23.   

    你生成的 静态页面肯定有公用的 脚本文件。。
    在这个脚本文件中加 个 ajax 请求的 代码
    将当前页面的document.title(或当前新闻的标识id) 传入到 ajax请求的ashx文件中ashx文件中通过sql更新操作点击量表(或者 你这个点击量可以直接在新闻表中加一列点击量)