JQuery + ajax implementation first, step on the result _ jquery

Source: Internet
Author: User
A lot of websites have the top features. when you step on the results, you can directly use the plug-ins that have been prepared by others. You just used this effect last week and went to study it. The following is a step-by-step implementation of the entire effect .... Demo page implementation

The Code is as follows:




This document is good.





70% (7000)



Document to be improved





30% (3000)




The main point is to control the g_img width by percentage. css code will not be pasted out.
DEMO code:

The Code is as follows:






Digg





This document is good.





70% (7000)



Document to be improved





30% (3000)






With the demo, other implementations are much more convenient. First, the page gets html. The page is loaded for the first time, and the background data is obtained using ajax instead of being directly displayed. (Asp is used as the background language for convenience of testing)
The following is the html code output by asp.

The Code is as follows:


Function getdigshtml () 'output html
Dim rsajax, SQL, str, digsnum, undigsnum, digsnumall, digsper, undigsper
Set rsajax = server. CreateObject ("adodb. recordset ")
SQL = "select * from dig where id = 1"
Rsajax. open SQL, conn, 1, 1
Digsnum = rsajax ("digs ")
Undigsnum = rsajax ("undigs ")
If isnull (digsnum) then digsnum = 0
If isnull (undigsnum) then undigsnum = 0
Digsnumdigsnumall = digsnum + undigsnum
If digsnumall = 0 then
Digsper = 0
Undigsper = 0
Else
Digsper = FormatNumber (cint (digsnum)/cint (digsnumall), 3) * 100
Undigsper = FormatNumber (cint (undigsnum)/cint (digsnumall), (3) * 100
End if
Str ="

"
Strstr = str &""
Strstr = str &"

This document is good.

"
Strstr = str & "" & digsper & "% (" & digsnum &")"
Strstr = str &"

"
Strstr = str &""
Strstr = str &"

Document to be improved

"
Strstr = str & "" & undigsper & "% (" & undigsnum &")"
Strstr = str &"

"
Getdigshtml = str
End function


After the output is complete, we will get the result from the front end. At this time, we will use jquery ajax. Why not use ajax directly? The reason is very simple. I won't ..... Let's take a look at the ajax code in jquery, which is very simple.

The Code is as follows:


Function getdigshtml () // obtain the top level and step on the html
{
$. Ajax ({
Type: 'post ',
Url: 'digg. asp ',
Data: 'Action = getdigshtml ',
Success: function (msg ){
$ ("# Digg" cmd.html (msg );
}
})
}


The output is complete, and the next step is the digs and undigs operations, which is similar to getting html code.

The Code is as follows:


Function isdigs (digtype) // top it down and step on it
{
$. Ajax ({
Type: 'post ',
Url: 'digg. asp ',
Data: 'Action = digs & digtype = '+ digtype,
/* BeforeSend: function (){
$ ("# Vote"). hide ();
$ ("# Loadings"). show ();
}. The ajax request displays the loading effect */
Success: function (msg ){
Switch (msg)
{
/* The backend is used to determine
Case '1 ':
$ ("# Loadings"). hide ();
$ ("# Vote"). show ();
Alert ("Please log on first! ");
Break;
Case '2 ':
$ ("# Loadings"). hide ();
$ ("# Vote"). show ();
Alert ("Download it first before proceeding! ");
Break;
Case '4 ':
$ ("# Loadings"). hide ();
$ ("# Vote"). show ();
Alert ("You have participated in the evaluation! ");
Break ;*/
Case '3 ':
Getdigshtml (); // rebind html
// $ ("# Loadings"). hide ();
// $ ("# Vote"). show ();
Alert ("Thank you for your participation! ");
Break;
Default:
}
}
})
}


Commented out code: part of the code is used for legal verification of Background Data. The beforeSend method is related to the operations before the ajax request is executed (for loading more)
The last step is to re-obtain and bind the getdigshtml () after each data submission and return a successful result, thus ensuring the real-time data.
The Demo code requires an asp environment. You can test it.
Packaging: http://www.jb51.net/jiaoben/28489.html

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.