Thursday, 8 February 2018

Setting the cache in jQuery $.post() to be false?

This is an old problem that seems to pop up from time to time and I am always scratching my head. This solution fixes the problem but it may not be suitable in all cases as it is in effect disabling a key feature of AJAX - The asynchronous feature. That said and done for the cases where I have had this problem - Apple products and Safari I'm looking at you especially - setting the additional parameter of async:false in your jQuery AJAX request fixes the issue and actually solves the "No Alert on Post Callback" problem.


As I said if you absolutely rely on asynchronous functionality then this is not going to help you, but for many projects it will stop you pulling your hair out.


$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType,
async:false
});

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...