I have this div in every document:
<div id="header" class="hide" style="top: 0px; width: 100%; z-index: 1000;">
And this script (in every document too):
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$("#loading-header").show();
$.ajax({
async: true,
type: 'GET',
url: '/PersonsAjax/Header',
data: {},
success: function (data) {
$("#loading-header").hide();
console.debug("Is there a header? " + $("#header").size());
$("#header").show(); // **** PROBLEM *****
}
});
}
My problem is:
I'm experiencing a very weird behaviour, two scenarios:
Scenario 1 (OK):
- Document is ready, #header is shown
- Click a link
- The new document is loaded and the #header is shown
Scenario 2 (problemo):
- Document is ready, #header is shown
- Do a browser's refresh (using F5 key)
- The new document is loaded but the #header is not always shown.
My first thought was: "the document is still loading, and maybe there isn't a #header yet", but my console.debug proved that this wasn't the problem
What is happening?
Is there a well known problem with jQuery's show() and doing refresh?
Please notice also that I'm preventing ajax calls to be cached. I double checked the ajax response and it brings the correct data