Solve the browser cache problem when using Ajax

Source: Internet
Author: User

In the latest project, Ajax is used to import and update data in batches. The first time the data is submitted normally, the same order is submitted later. The Order has been processed, but the interface still prompts that the order has not been processed.

 

I found the cause, which was originally caused by Ajax cache problems.

The solution is as follows:

 

1,Add the header ("cache-control: No-cache, must-revalidate") on the server (such as in PHP)

2,Add anyajaxobj. setRequestHeader ("If-modified-since", "0") before Ajax sends a request ");

3,Add anyajaxobj. setRequestHeader ("cache-control", "No-Cache") before sending a request through Ajax ");

4,Add "? Fresh = "+ math. Random (); // Of course, the fresh parameter can be any one here

5,The fifth method is similar to the fourth method. Add "? Timestamp = "+ new date (). gettime ();

6,Replacing get with post: Not recommended


Use the fourth solution in the project:Math. Random (). After this random parameter is added, the system is normal.

$. Ajax ({
Type: "Get ",
Async: False ,
URL: "../handler/k3importdeliveryhandler. ashx? Orderid = "+ Text [I] + '& time =' + math. Random (),
Beforesend: Function (XMLHttpRequest ){
$ ('# Loading'). Show ();
$ ('# Txtlog '). val ($ ('# txtlog '). val () + '[processing Order' + Text [I] + '...] \ n ');
},
Success: Function (Data, textstatus ){
$ ('# Txtlog'). Val ($ ('# txtlog'). Val () + Data + '\ n ');
},
Complete: Function (XMLHttpRequest, textstatus ){
$ ('# Loading'). Hide ('low ');
},
Error: Function (){
}
});

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.