ajax简单应用代码

作者:袖梨 2022-06-25

ajax简单应用代码

@ webhandler language="c#" class="handler" %>

using system;
using system.web;
using system.collections.generic;
using system.data;

public class handler : ihttphandler
{
public void getpage( httpcontext context)
{
int pagenum = convert.toint32(context.request["pagenum"]);

pagenum++;
if (pagenum {
dataset1.productdatatable cachedata =

(dataset1.productdatatable)context.cache["cachekey"];
if (cachedata == null)
{
cachedata = new

dataset1tableadapters.producttableadapter().getdatabypriceasc(1, 15);
context.cache.insert("cachekey", cachedata, null,

system.web.caching.cache.noabsoluteexpiration, timespan.fromseconds

(80));
}
list news = new list();
for (int i = (pagenum * 5) - 4; i {
dataset1.productrow row = cachedata[i - 1];
string s = link.toproduct(row.productid.tostring());
news.add(new product()
{
name = row.name,
description = row.description,
price = row.price.tostring(),
thumbnail = row.thumbnail,
path = s
});


}
system.web.script.serialization.网页特效serializer jss =

new system.web.script.serialization.网页特效serializer();
context.response.write(jss.serialize(news));
}

else
{

var data = new

dataset1tableadapters.producttableadapter().getdatabypriceasc((pagenum *

5) - 4, pagenum * 5);

list news = new list();
for (int i =0; i {
dataset1.productrow row = data[i];
string s = link.toproduct(row.productid.tostring());
news.add(new product()
{
name = row.name,
description = row.description,
price = row.price.tostring(),
thumbnail = row.thumbnail,
path = s
});


}
system.web.script.serialization.javascriptserializer jss

= new system.web.script.serialization.javascriptserializer();
context.response.write(jss.serialize(news));

}

}
public void processrequest (httpcontext context)
{
context.response.contenttype = "text/plain";
string action = context.request["action"];
if (action == "getpage")
{
int allcount = new

dataset1tableadapters.producttableadapter().getcount().value;
context.response.write(allcount);

}
else if (action == "getpagedateasc")
{

getpage("getpagedateasc", context);
}
else if (action == "getpagedatedesc")
{
getpage("getpagedatedesc", context);
}

}


public bool isreusable
{
get
{
return false;
}
}

}
public class product
{
public string name { set; get; }
public string description { set; get; }
public string price { set; get; }
public string thumbnail { set; get; }
public string path { set; get; }

}


html代码//http://www.*3p*p*t.com/design/asp教程x/38279.html

"">

http://www.***w3.org/1999/xhtml">



rel="stylesheet" type="text/css" />


children/message-balloons/page=" + parseint(this.innerhtml);
}
});
}

var data;
$(function () {
$.post("handler.ashx", { "action": "getpage" }, function

(data123, status) {
data=data123;
initdata(0);

});

});

function pageselectcallback(page_id, jq) {
initdata(page_id);
return false;
};


function initdata(pageindx) {

$.post("handler.ashx", { "action": "getpagedate",

"pagenum": pageindx }, function (data, status) {

if (status == "success") {
var datas = $.parsejson(data);
$("#myul").empty();
for (var i = 0; i var p = datas[i];
var li = $("

  • " + "

    class='producttitle'> "

    +
    "" + ""

    +p.description+"

    class='detailsection'>+ price:"+p.price+"

  • ");




    $("#myul").append(li);






    }

    };


    });

    $("#pagination").pagination(data, {
    callback: pageselectcallback,
    prev_text: ' next_text: '下一页 >>',
    items_per_page: 5,
    num_display_entries: 4,
    current_page: pageindx,
    num_edge_entries: 1
    });
    createlink();
    }








      "">

      http://www.***w3.org/1999/xhtml">



      rel="stylesheet" type="text/css" />


      children/message-balloons/page=" + parseint(this.innerhtml);
      }
      });
      }

      var data;
      $(function () {
      $.post("handler.ashx", { "action": "getpage" }, function

      (data123, status) {
      data=data123;
      initdata(0);

      });

      });

      function pageselectcallback(page_id, jq) {
      initdata(page_id);
      return false;
      };


      function initdata(pageindx) {

      $.post("handler.ashx", { "action": "getpagedate",

      "pagenum": pageindx }, function (data, status) {

      if (status == "success") {
      var datas = $.parsejson(data);
      $("#myul").empty();
      for (var i = 0; i var p = datas[i];
      var li = $("

    • " + "

      class='producttitle'> "

      +
      "" + ""

      +p.description+"

      class='detailsection'>+ price:"+p.price+"

    • ");




      $("#myul").append(li);






      }

      };


      });

      $("#pagination").pagination(data, {
      callback: pageselectcallback,
      prev_text: ' next_text: '下一页 >>',
      items_per_page: 5,
      num_display_entries: 4,
      current_page: pageindx,
      num_edge_entries: 1
      });
      createlink();
      }






        相关文章

        精彩推荐