Digg top step (jquery + Ajax)

Source: Internet
Author: User
Tags set cookie
//Default.aspx
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

 

 

// Digg. aspx

Using system; using system. data; using system. configuration; using system. collections; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; public partial class Digg: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string S = request ["ID"]. tostring (); int aid = Int. parse (s); If (request ["action"]! = NULL) // you must specify this {string action = request ["action"]. tostring (); DB d = new dB (); If (Action = "good") {d. excutesql ("Update Digg set goodpost = goodpost + 1, lastpost = getdate () Where contentid =" + aid);} else if (Action = "bad") {d. excutesql ("Update Digg set badpost = badpost + 1, lastpost = getdate () Where contentid =" + aid) ;}} string Ss = getdigg (AID); response. write (SS) ;}public string getdigg (INT Strid) {int goodper; int badper; string Digg = ""; DB d = new dB (); datatable dt = D. getdt ("select goodpost, badpost from Digg where contentid =" + Strid); foreach (datarow DR in DT. rows) {int goodposts = convert. toint32 (Dr ["goodpost"]); int badposts = convert. toint32 (Dr ["badpost"]); If (goodposts + badposts = 0) {goodper = badper = 0;} else {int balls = goodposts + badposts; goodper = convert. toint32 (double) goodposts/balls * 100); badper = 100-goodper;} Digg + = "<Div class = \" diggbox digg_good \ "onmousemove = \" this. style. backgroundposition = 'left bottom '; \ "onmouseout = \" this. style. backgroundposition = 'left top'; \ "onclick = \" postdigg ('good', "+ Strid +") \ "> "; digg + = "<Div class = \" digg_act \ "> top </div> "; digg + = "<Div class = \" digg_num \ "> (" + goodposts + ") </div> "; digg + = "<Div class = \" digg_percent \ ">"; Digg + = "<Div class = \" digg_percent_bar \ "> <span style = \" width: "+ goodper +" % \ "> </span> </div> "; digg + = "<Div class = \" digg_percent_num \ ">" + goodper + "% </div>"; Digg + = "</div> "; digg + = "</div>"; Digg + = "<Div class = \" diggbox digg_bad \ "onmousemove = \" this. style. backgroundposition = 'right bottom '; \ "onmouseout = \" this. style. backgroundposition = 'right top'; \ "onclick = \" postdigg ('bad', "+ Strid +") \ "> "; digg + = "<Div class = \" digg_act \ "> click </div> "; digg + = "<Div class = \" digg_num \ "> (" + badposts + ") </div> "; digg + = "<Div class = \" digg_percent \ ">"; Digg + = "<Div class = \" digg_percent_bar \ "> <span style = \" width: "+ badper +" % \ "> </span> </div> "; digg + = "<Div class = \" digg_percent_num \ ">" + badper + "% </div>"; Digg + = "</div> "; digg + = "</div>" ;}return Digg ;}}

 

// Cookie. js

// Read/write cookie function getcookie (c_name) {If (document. Cookie. length> 0) {c_start = Document. Cookie. indexof (c_name + "=") if (c_start! =-1) {c_start = c_start + c_name.length + 1; c_end = document. cookie. indexof (";", c_start); If (c_end =-1) {c_end = document. cookie. length;} return Unescape (document. cookie. substring (c_start, c_end);} return NULL} function setcookie (c_name, value, expiredays) {var exdate = new date (); exdate. setdate (exdate. getdate () + expiredays); document. cookie = c_name + "=" + escape (value) + (expiredays = Null )? "": "; Expires =" + exdate. togmtstring (); // make the set effective time correct. Add togmtstring ()}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.