Simple implementation of ajax without refreshing pages and ajax refreshing pages
The examples in this article share with you the code for refreshing pages in ajax for your reference. The details are as follows:
Html page
<Html>
WebService1.asmx
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. services; using System. data; namespace paging {// <summary> // summary of WebService1 /// </summary> [WebService (Namespace =" http://tempuri.org/ ")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. [System. web. script. services. scriptService] public class WebService1: System. web. services. webService {[WebMethod] public string HelloWorld () {return "Hello World";} [WebMethod] public List <Model. t_News1> GetListAjax (int pagesize, int pageindex) {BLL. t_News1 bnews = new BLL. t_News1 (); DataTable dt = bnews. getListDataTable (pagesize, pageindex); List <Model. t_News1> list = new List <Model. t_News1> (); int Id; string newstitle = ""; string newscontent = ""; DateTime createtime; for (int I = 0; I <dt. rows. count; I ++) {Id = Convert. toInt32 (dt. rows [I] ["Id"]); newstitle = dt. rows [I] ["NewsTitle"]. toString (); newscontent = dt. rows [I] ["NewsContent"]. toString (); createtime = Convert. toDateTime (dt. rows [I] ["CreateTime"]); Model. t_News1 news = new Model. t_News1 () {Id = Id, NewsTitle = newstitle, NewsContent = newscontent, CreateTime = createtime}; list. add (news) ;}return list;} [WebMethod] public int GetLastPageindex (int pagesize) {BLL. t_News1 bnews = new BLL. t_News1 (); int totalcount = bnews. getRecordCount (""); if (totalcount % pagesize = 0) {return totalcount/pagesize;} else {return totalcount/pagesize + 1 ;}}}}
The above is the key code for implementing the implementation of ajax without refreshing pages. I hope it will be helpful for your learning.