PHP development red and blue voting function tutorial jQuery
When the hand button is clicked, jQuery's $.getJSON() is used to send an Ajax request to the background php. If the request is successful, the json data returned by the background will be obtained, and jQuery will process the json data. The following function: getdata(url,sid), passes two parameters. URL is the backend PHP address of the request, and sid represents the current voting topic ID. In this function, the json data returned includes the number of votes from both red and blue parties, and The ratio of both parties, calculate the width of the proportion bar based on the ratio, and display the voting effect asynchronously interactively.
$.getJSON(url,{id:sid},function(data){
if(data.success==1){
. red").css("width",data.red_percent*100+"%");
var red_bar_w = w*data.red_percent-10;
"#red_bar").css("width",red_bar_w);
").css("width",data.blue_percent*100+"%");
blue_bar_w blue_bar_w ").css("width", blue_bar_w);
When the page is loaded for the first time, getdata() is called, and then click to vote for the red team or vote for the blue team to also call getdata(), but the parameters passed are different. Note that the parameter sid in this example is set to 1, which is set based on the id in the data table. Developers can read the accurate id based on the actual project.
//Get initial data
getdata("vote.php",1);
//Red team vote
$( ".redhand").click(function(){
getdata("vote.php?action=red",1);
.bluehand").click(function(){
getdata("vote.php?action=blue",1);
});
});
- Course Recommendations
- Courseware download
-
AdvancedjQuery red and blue voting function practical tutorial
8756 people are watching -
ElementaryScala Tutorial
13129 people are watching -
ElementaryCSS Online Manual
81586 people are watching -
ElementarySVG Tutorial
12670 people are watching -
ElementaryAngularJS Chinese Reference Manual
24116 people are watching -
ElementaryGo language tutorial manual
26875 people are watching -
ElementaryRedis command operation Chinese manual
57400 people are watching -
ElementaryPython 3 Tutorial
87111 people are watching -
ElementaryXML DOM tutorial
20649 people are watching -
ElementaryMemcached command operation manual
17434 people are watching -
ElementaryXSLT tutorial
9516 people are watching -
ElementaryXQuery Tutorial
8835 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)