Home Web Front-end JS Tutorial Ajax caching problem under IE8/IE9

Ajax caching problem under IE8/IE9

May 23, 2018 pm 04:49 PM
ajax ie cache

This article introduces to you the solution to the Ajax cache problem under IE8/IE9. It is very good and has reference value. Friends who are interested should take a look at it together

ajax introduction

AJAX stands for "Asynchronous Javascript And XML" (asynchronous JavaScript and XML), which refers to a web development technology for creating interactive web applications.

AJAX = Asynchronous JavaScript and XML (a subset of Standard Universal Markup Language).

AJAX is a technology for creating fast, dynamic web pages.

By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. This means that parts of a web page can be updated without reloading the entire page.

Let’s get to the point:

I am currently working on a login registration box for a website, using jquery on the front end. Since sign and login are not on separate pages, they appear in a pop-up box. So I decided to use ajax to implement the registration and login functions. I thought it would be smooth sailing, but I discovered a strange problem during the test.

There is basically no problem when testing with chrome, ff, and IE10. However, when running on IE8 and 9, it appears that I cannot log in after entering the correct user name and password. At first, I thought the session was lost and started complaining about the background framework.

But after patient debugging, I found that the session was not lost. I'm really worried now. Is it possible that I can't even register and log in after being around for so long? This makes me belittle myself and lament the various changes in life and the impermanence of things. After burning incense for 1/3 of the time, I decided to cheer up.

After carefully observing my code with few comments, I found that the url in $.ajax was a bit strange. Although the address is correct, the intuition of programmers and siege lions tells me that the two brothers IE8 and 9 may have cached my ajax on their own initiative. Thinking of this, my hands suddenly trembled, and I hurriedly added a timestamp after the URL.

//就像这样url:myurl+"?t="+(new Date).valueOf()
Copy after login

Then clear the cache and try again, success! You can log in normally.

After checking Baidu, it turns out that under IE8 9, when making an Ajax request, if it is the same as the previous request, the data will not be obtained from the server, but directly obtained locally.

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

cache:

It is required to be a parameter of Boolean type. The default is true (when the dataType is script, the default is false). If set to false, the request information will not be loaded from the browser cache.

Or set it globally (not tested)

//$.ajaxSetup() 方法设置全局 AJAX 默认选项。$.ajaxSetup({ cache: false });
Copy after login

Then you don’t have to worry about caching.

However, the cache is not set up to cause us trouble. After all, other browsers can use it normally. Therefore, it is necessary to set up a separate setting for IE8 9 to disable the information in the cache.

//jquery 1.9.0后取消了$.browserif($.browser.msie&&($.browser.version=="8.0"||$.browser.version=="9.0")){
//做处理 
}
Copy after login

After 1.9.0, you can use $.support to judge

// IE6789,input元素的checked属性不能被拷贝// IE下,input被更换类型后,无法保持前一个类型所设的值if(!$.support.radioValue&&!$.support.noCloneChecked){
//做处理 
}
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

The problem that IE8 cannot be refreshed every time when using ajax access

Ajax calls the restful interface to transmit Json format data Method (with code)

Ajax and cgi communication under Boa server (graphic tutorial)

The above is the detailed content of Ajax caching problem under IE8/IE9. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view and refresh dns cache in Linux How to view and refresh dns cache in Linux Mar 07, 2024 am 08:43 AM

DNS (DomainNameSystem) is a system used on the Internet to convert domain names into corresponding IP addresses. In Linux systems, DNS caching is a mechanism that stores the mapping relationship between domain names and IP addresses locally, which can increase the speed of domain name resolution and reduce the burden on the DNS server. DNS caching allows the system to quickly retrieve the IP address when subsequently accessing the same domain name without having to issue a query request to the DNS server each time, thereby improving network performance and efficiency. This article will discuss with you how to view and refresh the DNS cache on Linux, as well as related details and sample code. Importance of DNS Caching In Linux systems, DNS caching plays a key role. its existence

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

PHP and Ajax: Building an autocomplete suggestion engine PHP and Ajax: Building an autocomplete suggestion engine Jun 02, 2024 pm 08:39 PM

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

Advanced Usage of PHP APCu: Unlocking the Hidden Power Advanced Usage of PHP APCu: Unlocking the Hidden Power Mar 01, 2024 pm 09:10 PM

PHPAPCu (replacement of php cache) is an opcode cache and data cache module that accelerates PHP applications. Understanding its advanced features is crucial to utilizing its full potential. 1. Batch operation: APCu provides a batch operation method that can process a large number of key-value pairs at the same time. This is useful for large-scale cache clearing or updates. //Get cache keys in batches $values=apcu_fetch(["key1","key2","key3"]); //Clear cache keys in batches apcu_delete(["key1","key2","key3"]);2 .Set cache expiration time: APCu allows you to set an expiration time for cache items so that they automatically expire after a specified time.

The relationship between CPU, memory and cache is explained in detail! The relationship between CPU, memory and cache is explained in detail! Mar 07, 2024 am 08:30 AM

There is a close interaction between the CPU (central processing unit), memory (random access memory), and cache, which together form a critical component of a computer system. The coordination between them ensures the normal operation and efficient performance of the computer. As the brain of the computer, the CPU is responsible for executing various instructions and data processing; the memory is used to temporarily store data and programs, providing fast read and write access speeds; and the cache plays a buffering role, speeding up data access speed and improving The computer's CPU is the core component of the computer and is responsible for executing various instructions, arithmetic operations, and logical operations. It is called the "brain" of the computer and plays an important role in processing data and performing tasks. Memory is an important storage device in a computer.

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

How to save video files from browser cache to local How to save video files from browser cache to local Feb 23, 2024 pm 06:45 PM

How to Export Browser Cache Videos With the rapid development of the Internet, videos have become an indispensable part of people's daily lives. When browsing the web, we often encounter video content that we want to save or share, but sometimes we cannot find the source of the video files because they may only exist in the browser's cache. So, how do you export videos from your browser cache? This article will introduce you to several common methods. First, we need to clarify a concept, namely browser cache. The browser cache is used by the browser to improve user experience.

See all articles