文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Jquery 请求ashx

Jquery 请求ashx

时间:2010-09-21  来源:爱上狗的狐狸

 做了一个文章列表,要实现增删改查功能,以前常用用ajax方法中的(ajaxpro),jquery也行,那就用jquery吧,小试一下牛刀

以前做数据删除的时候都有去aspx页请求的,后来知道用ashx会更快些,以下是方法

jquery方法

 

代码 function buildxml()
     {
      
             $.ajax({
                type: "get",
                url: "/db/AjaxHelp.ashx",
                data:'buildxml=1',
                beforeSend: function(XMLHttpRequest){             
                  
                  
                    //ShowLoading();
                },
                success: function(data, textStatus){               
                  alert('OK'); alert(data);
                },
                complete: function(XMLHttpRequest, textStatus){
                    //HideLoading();
                },
                error: function(){
                    alert('error');
                }
                    });

 

 

 

 

以下是ashx方法

代码   public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
           // context.Response.Write("Hello World");
            string buildxml =context.Request.QueryString["buildxml"].ToString();
            if (buildxml == "1")
            {
                if (CreateXML())
                {
                    context.Response.Write("生成成功!");
                }
                else
                {
                    context.Response.Write("生成失败!");
                }
            }
        }



        private bool CreateXML()
        {
            try
            {

                DB.DBHelperDataContext bll = new DBHelperDataContext();
                var q = (from s in bll.IndexNews
                         where s.Types==1
                         orderby s.ID descending
                         select new{s.ID,s.Title}).Take(3);
               

                string topNews = System.Configuration.ConfigurationManager.AppSettings["topNews"].ToString();

              //  DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.SSCSConnectString, CommandType.Text, sqlStr);




                int i=0;

               foreach(var m in q)
               {
                  
                   string id = m.ID.ToString();
                   string name = m.Title.Length>18?m.Title.Substring(0,18):m.Title;
                  
                    if (i == 0)
                    {
                        XmlParameter[] param = { new XmlParameter("id", id), new XmlParameter("name", name) };
                        XMLHelper.CreateXMLFile(topNews, new XmlParameter("books"), "chapter", param);
                    }
                    else
                    {
                        XmlParameter[] aparam = { new XmlParameter("id", id), new XmlParameter("name", name) };
                        XMLHelper.AddNewNode(topNews, "books", aparam);

                    }
                    i++;
                }
             
            }
            catch (Exception ex) { PageHelper.Alert(ex.ToString()); return false; }
            return true;

        }

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载