Ajax cache in IE8 and 9, and ajax cache in ie89

Source: Internet
Author: User

Ajax cache in IE8 and 9, and ajax cache in ie89

Recently, in the login registration box for a website, jquery is used at the front end. Because the sign and login are not on a separate page, they are displayed in a pop-up box. Therefore, we decided to use ajax to implement the registration and login functions. I thought it would be smooth sailing, and I found a strange problem during the test.

When chrome, ff, and IE10 + are used for testing, there is basically no problem. However, when running on IE8 and 9, you cannot log on with the correct username and password. At first, I thought the session was lost and began to talk about the background framework.

However, after a patient debugging, we found that the session was not lost. Now, I am in a hurry. Is it impossible to get a registered login after such a long time? This allows me to be arrogant and lament the impermanence of life. Then, after being 1/3 fragrant, I decided to cheer up.

After carefully observing the code without a few comments, I found that the url in $. ajax is a bit strange. Although the address is correct, the intuition of programmers and siege lions tells me that IE8 9 May cache my ajax on their own. Think of this, his hands suddenly trembling, panic added a timestamp after the url.

// Like this
Url: myurl + "? T = "+ (new Date). valueOf ()

Then clear the cache and try again! You can log on normally.

I checked Baidu. It turns out that in IE8 9, if the Ajax request is the same as the previous request, no data will be obtained from the server, but directly from the local machine.

In this way, you can set the cache attribute to false (not tested) when using $. ajax to deal with the excessive enthusiasm of earlier versions of IE ),

      Cache:

A Boolean parameter is required. The default value is true. If dataType is set to script, the default value is false. If it is set to false, request information is not loaded from the browser cache.

Or set it globally (not tested)

// $. AjaxSetup () method to set the global AJAX default options.
$. AjaxSetup ({cache: false });

This eliminates the need to worry about caching.

However, the cache is not set to cause us trouble. After all, other browsers can work normally. Therefore, you must separately disable the information in the cache for IE8 9.

// Jquery 1.9.0 is canceled after $. browser
If ($. browser. msie & ($. browser. version = "8.0" | $. browser. version = "9.0") {// processing}

After 1.9.0, you can use $. support to determine

  

// IE6789, the checked attribute of the input element cannot be copied
// In IE, after the input type is changed, the value of the previous type cannot be kept
If (! $. Support. radioValue &&! $. Support. noCloneChecked) {// processing}

$. Support is mainly used inside jQuery, and it is not easy to use at all.

If there is an error or a better solution, please leave a message to me.

 

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.