Below to share the AJAX read txt and the TXT content page to display the core code, nonsense said more, directly affixed to the code.
function transferstring (content) {var string = content; try{string=string.replace (/\r\n/g, "<BR>") string=string
. replace (/\n/g, "<BR>"); String=string.replace (/[]/g, " ") String=string.replace (/\ +/g, " ")}catch (e) {alert (e.message);} return
String
} var pageIndex = 1;
var id = $ ("#aId"). Val ();
var url = $ (' #urlArticleContent '). Val ();
var txt = ';
var pageSize = @ (configurationmanager.appsettings["articlepagesize"]);
var page=5;
var pagecount = 0; $ (function () {if (url!= "") {txt = ($.ajax ({url:url, async:false})). responsetext; if (Txt.indexof (' HTTP://WWW.W3.ORG/1 999/xhtml ') ==-1) {PageCount = Math.ceil (txt.length/pagesize); $ ("#PageCount"). HTML (PageCount); $ (' #word '). HTML (
Transferstring (txt.substring (0, pageSize)); $ (' #demo '). Pagination ({datasource:function) {var result = []; for (var i = 1; i < PageCount; i++) {Result.push (
i);
(result); }, Pagecount:pagecount, Pagesize:5, Showgoinput:true, Showgobutton:true, callback:function (datA, pagination) {//template method of yourself var html = template (data); datacontainer.html (HTML);}})
} else {txt = ';}} function Gohead () {gopage (1);} function Nextclick () {if (PageIndex < PageCount) {PageIndex = PageIndex + 1;} El
se {pageIndex = PageCount;}
Gopage (PageIndex);
$ ("#pageCurrent"). HTML (PAGEINDEX);
The function Backclick () {if (PageIndex > 1) {pageIndex = pageIndex-1;
Gopage (PageIndex);
$ ("#pageCurrent"). HTML (PAGEINDEX);
The function gopagenew () {var page=$ ("#pageGo"). Val ();
Gopage (page);
Opts.current=page; } function Gopage (PageIndex) {if (pageindex==0) {pageindexstr = $ (' #goPage '). Val (); if (pageindexstr==undefined) {return
False
} pageindexstr = Pageindexstr.trim ();
var pageIndex = parseint (PAGEINDEXSTR);
} $ (' #page ' +pageindex). Siblings (). Removeclass (' active ');
$ (' #page ' +pageindex). addclass (' active '); if (pageindex==1) {if (!$ (' #backClick '). Hasclass (' disabled ')) {$ (' #backClick '). addclass (' disabled ');}} else {$ (' # Backclick '). Removeclass(' disabled '); } if (PageIndex = = PageCount) {if (!$ (' #nextClick '). Hasclass (' disabled ')) {$ (' #nextClick '). addclass (' disabled ');} els e {$ (' #nextClick '). Removeclass (' disabled ');} var pagetxt = txt.substring ((pageIndex-1) * pageSize, PageIndex * pagesiz
e);
$ (' #word '). HTML (transferstring (pagetxt));
$ (' HTML, Body '). Animate ({' scrolltop ': 0}, 0);
$ ("#pageCurrent"). HTML (PAGEINDEX); function Pagego () {if ($ ('. Jump-ipt '). Val ()!= ') {gopage ($ ('. Jump-ipt '). Val ())} @{if (null!= viewbag.ariticle) {Dat
Arow dr = Viewbag.ariticle; if (null!= dr) {viewbag.title = dr["Title"]; <div class= "container" > <div class= "Row" > <div class= "Col-xs" -12 > <div class= Breadcrumb_block > <span class= ><a href=/web/sciencefiction/index > Popular Science ip</a> ></span> <ol class= "breadcrumb" > <li class= "Active" > @dr ["Title"]</li> < Li class= "active" > Online probation </li> </ol> <div class= "clear" ></div> </div> </div> ≪div class= "Col-sm-8" > <input type= "hidden" name= "aid" id= "aid" value= "@Request [" id "]"/> <div class= " Read_book ">
TXT file upload needs to do some processing, otherwise can only display UTF8 format txt
<summary>///File Upload///</summary>///<returns></returns> public Jsonresult uploadfiles () {
HttpPostedFileBase postfile = httpcontext.request.files["FileSave"]; if (postfile!= null) {string filename = Path.getfilename (postfile.filename); string fileext = Path.getextension (fileName .
ToLower ());
String fileSize = PostFile.ContentLength.ToString ();
Long Filenametem = Common.generatelongid (); String spath = String. Format ("/data/material/{0}_{1}.txt", filenametem.tostring (), Filename.replace (". txt", ""));//guid.newguid (). ToString (). Replace ("-", "") string Viewurl = String.
Empty; String g = Guid.NewGuid ().
ToString (); if (! Directory.Exists (Server.MapPath ("~") + "/data/material") Directory.CreateDirectory (Server.MapPath ("~") + "/Data/"
Material ");
String p = Server.MapPath (spath);
Postfile.saveas (P);
if (System.IO.File.Exists (p)) {StreamReader sr = new StreamReader (p, System.Text.Encoding.Default); String input = Sr.
ReadToEnd (); Sr.
Close (); StreamWriter sw = NEW StreamWriter (P, False, System.Text.Encoding.UTF8); Sw.
WriteLine (input); Sw.
Close ();
Return Json (New {FilePath = spath, filename = filename, Viewurl = viewurl, fileSize = fileSize});
else {return Json (new {FilePath = ""});}
Another page to introduce the first JS
<script src= "~/scripts/web/jquery.pagination.js" ></script> <link href= "~/content/" Jquery.pagination.css "rel=" stylesheet/>/** * Pagination Paging plugin * @version 1.1.2 * @author MSS * @url Http://maxiaoxian
g.com/plugin/pagination.html * @e-mail 251445460@qq.com * * * * $ (selector). pagination (); * * Update log * 2016-07-25: Repair Click Repeat event * *; (Function ($, window, document, undefined) {//configuration parameter var defaults = {totaldata:0,//Data total number of bars showdata:0,//per page display number of bars Pagecoun T:9,//Total number of pages, defaults to 9 current:1,//Current page prevcls: ' prev ',//prev class Nextcls: ' Next ',//Next class Prevcontent: ' prev ',//previous page content n Extcontent: ' next page ',///Next page Content activecls: ' active ',//Current page selected state Coping:false,//Home and Last homepage: ',//Homepage node content endpage: ',//last section Point content Count:5////////////////////////////////////////////////////////////////Jump:true
Turn ',//Jump button text Callback:function () {}//callback}; var pagination = function (element, options) {//global variable var opts = options,//configuration current,//Current Page $document = $ (document), $obj = $ (Element),//Container/** * Set Total pages * @param int page number * @return opts.pagecount Total Page Configuration * * This.settotalpage = funct
Ion (page) {return opts.pagecount = page;}; /** * Get total pages * @return int p Total pages */this.gettotalpage = function () {var p = Opts.totaldata | | opts.showdata?
Math.ceil (parseint (opts.totaldata)/opts.showdata): Opts.pagecount;
return p;
};
Gets the current page this.getcurrent = function () {return;}; /** * Fill data * @param int index page */this.filling = function (index) {var html = '; current = Index | | opts.current;//page
Code var PageCount = This.gettotalpage (); if (current > 1) {//prev HTML + + ' <li onclick=gopage (' + (current-1) + ') ><a href= ' javascript:; "class=" ' + O Pts.prevcls + ' > ' + opts.prevcontent + ' </a></li> ';} else {$obj. Find ('. ' + opts.prevcls) && $obj. Find ('. ' + opts.prevcls). Remove ();} if (Current >= Opts.count * 2 && current!= 1 && pagecount!= opts.count) {var home = opts.coping && opts.hoMepage?
Opts.homepage: ' 1 '; html = opts.coping? ' <li onclick=gopage (' + Home + ') ><a href= "javascript:;" data-page= "1" > ' + Home + ' </a></li><s
Pan>...</span> ': ';
var start = current-opts.count, end = current + Opts.count;
(Start > 1 && Current < Opts.count) | |-current = = 1) && end++;
(Current > Pagecount-opts.count && current >= pagecount) && start++; for (; Start <= end; start++) {if (Start <= pagecount && start >= 1) {if (start!= current) {html = ' <li onclick=gopage (' + start + ') ><a href= "javascript:;" data-page= "' + Start + '" > ' + start + ' </a><
/li> '; else {html = ' <li class= ' + opts.activecls + ' "onclick=gopage (' + start + ') ><a href=" javascript:; "
><span> ' + start + ' </span></a></li> '; }} if (current + Opts.count < PageCount && >= 1 && pagecount > Opts.count) {var enD = opts.coping && opts.endpage?
Opts.endPage:pageCount; html = opts.coping? ' <span>...</span><li onclick=gopage (' + PageCount + ') ><a href= "javascript:;" data-page= "' +
PageCount + ' > ' + end + ' </a></li> ': ';} if (current < PageCount) {//Next page HTML + + ' <li onclick=gopage (' + (current + 1) + ') ><a href= "javascript:;" Clas s= "' + opts.nextcls + '" > ' + opts.nextcontent + ' </a></li> '} else {$obj. Find ('. ' + opts.nextcls) &&am P
$obj. Find ('. ' + opts.nextcls). Remove (); html = opts.jump? ' <input type= ' text ' class= ' + opts.jumpiptcls + ' "><a href=" javascript:; "Onclick=pagego () class=" ' + opts.jump
Btncls + ' > ' + opts.jumpbtn + ' </a> ': ';
$obj. Empty (). HTML (HTML);
}; Binding Event This.eventbind = function () {var self = this; var PageCount = This.gettotalpage ();//Total pages $obj. Off (). On (' Click ', ' a ', function () {if ($ (this). Hasclass (Opts.nextcls)) {var index = parseint ($obj. Find ('. ' + opts.activeCls). Text () + 1; else if ($ (this). Hasclass (Opts.prevcls)) {var index = parseint ($obj. Find ('. ' + opts.activecls). Text ())-1;} else if ( $ (this). Hasclass (OPTS.JUMPBTNCLS) {if $obj. Find ('. ' + opts.jumpiptcls). Val ()!== ') {var index = parseint ($obj. Find ('
. ' + opts.jumpiptcls). Val ()); else {return;}}
else {var index = parseint ($ (this). Data (' page ');} self.filling (index);
typeof Opts.callback = = ' function ' && opts.callback (self);
});
Enter the page number of the Jump $obj. On (' Input PropertyChange ', '. ' + opts.jumpiptcls, function () {var $this = $ (this); var val = $this. val ();
var reg =/[^\d]/g;
if (Reg.test (val)) {$this. val (Val.replace (Reg, '));}
(parseint (val) > PageCount) && $this. Val (PageCount);
if (parseint (val) = = 0) {//Minimum value is 1 $this. val (1);}}); Return jump Specifies the page number $document. KeyDown (function (e) {var self = this; if (E.keycode = && $obj. Find ('. ' + OPTS.JUMPIPTCL
s). Val () {var index = parseint ($obj. Find ('. ' + opts.jumpiptcls). Val ());
Gopage (index); Self.fillinG (index);
typeof Opts.callback = = ' function ' && opts.callback (self);
}
});
};
Initialize this.init = function () {this.filling (opts.current), This.eventbind ();
This.init ();
}; $.fn.pagination = function (parameter, callback) {if (typeof parameter = = ' function ') {//overload callback = parameter; Paramet
ER = {}; else {parameter = parameter | |
{}; Callback = Callback | |
function () {};
var options = $.extend ({}, defaults, parameter);
Return This.each (function () {var pagination = new Pagination (this, options); callback (pagination);});
}; }) (JQuery, window, document);
The above is a small set up to introduce the AJAX read txt and TXT content for the paging display, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!