views:

943

answers:

1

The page in question is http://matthewanderson.cc

I'm a javascript newbie working on a WordPress-based portfolio site. I'm using jQuery .load() to fetch content from WordPress posts, and it works in Firefox, Safari and Chrome, but not any of the IEs.

The specific Ajax code is here:

$(document).ready(function(){
$("a.ajax-load").click(function (event) {
//prevent standard browser link behavior
event.preventDefault();
//Fade out any existing visible content
$("#project-expanded *:visible").fadeOut("slow");
//Insert loading graphic
$("#project-expanded").html('<p style="text-align:center;"><img src="http://matthewanderson.cc/wp-content/themes/tiles/ajax-loader.gif" width="16" height="16" style="margin:160px 0 0"/></p>');
//Pull URL from clicked object, store it in a variable, add string " #ajax-content" to be used in next line
var postAjaxURL = $(this).attr("href") + ' #ajax-content';
//Fetch content from the URL contained in postAjaxURL (filtering for #ajax-content), insert results into #project-expanded
$("#project-expanded").load( postAjaxURL, function(){
  //Set CSS contents of #project-expanded to display:none so they can be faded in later
  $("#project-expanded *").css("display","none");
  //Expand #project-expanded using jQuery .show effect
  $("#project-expanded").show("slow", function(){
    //After #project-expanded is expanded, fade in the contents
    $("#project-expanded *").fadeIn("slow");   
  });
});
});

I've added the following headers to all the pages being fetched to prevent IE caching, but it doesn't seem to help

<?
//Set no caching
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Anybody have any thoughts?

UPDATE:

It's probably prudent to mention that none of the versions of IE are reporting any javascript errors.

Also, I don't think it's a caching issue. After watching the page requests being made with Fiddler, I can see that content from outside the page is being successfully called.

+1  A: 

Another thing you can do is append something like &rand=230948234 to the url you are pulling. This will often force the browser to re-download it, since it doesn't know that the parameter is meaningless. This would generate a suitable random element:

var randomnumber=Math.floor(Math.random()*100000000);
var postAjaxURL = $(this).attr("href") + ' #ajax-content';
$("#project-expanded").load( postAjaxURL, {rand: randomnumber}, function(){

EDIT: Fixed! URL Parameters are not set the way I originally had it.

lod3n
Hmm... adding that seems to break it in FF, too. I'm copying and pasting your two lines of code in place of the one where I declared var postAjaxURL. Is that the right way to implement what you're talking about?
Ben Blank
Please check it again, I incorrectly added the URL parameters to the URL string, which is not how it's done in jQuery.
lod3n
Hey man, thanks for your efforts.still no luck though, unfortunately. Is it possible that it's not a caching issue?
Maybe. Also check your IE settings, under Tools, Internet Options, General tab, Browsing History, Settings button, change the radio button to Every Time I Visit The Webpage. If that doesn't solve it, no, it's not a caching issue.
lod3n