Two ways of Not refreshing page change verification code in web page

Source: Internet
Author: User

To do a registered page today, you need to enter a verification code. Verification code generation is dynamic, but to refresh the page, you can change the verification code, because after the browser will submit a new request to the server, the server will dynamically generate a new verification code response to the browser. To be able to change the verification code without refreshing the page, JavaScript support is required.

The first approach is to take parameters after the request address, which is a small trick. Because the browser accesses the server when the address can be passed along with parameters to the server, and loading content is only to see the address of the following parameters, in addition to , as long as the browser found that the address changes will automatically reload the address to the picture. So just give the address back with the current time parameter then the address is always different, so that the browser think the address changed to reload the captcha image. The specific approach is:In this way, you can automatically change the parameters of the SRC address when the mouse clicks on the image, thus enabling automatic loading.

The second method is to write a JavaScript method, click the link on the call to change the address of the method to achieve automatic change. The specific methods are:
<script type= "Text/javascript" >
function Changeverifycode () {
var img = document.getelementbyidx (' Imgvcode ');//in getting Id=imgvcode object
var time = new Date (). GetTime ();//Get current
img.src = img.src + '? ' + time;//splicing the address of SRC in IMG, with the same purpose as the first method
}
</script>

the place to call is anywhere after.
<a href= "Javascript:verifycode ()" > Can't see clearly? Change the verification code by a different image </a> click ^_^

This is intercepted from the Internet and is for personal collection only.

Two ways of Not refreshing page change verification code in web page

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.