Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery load() doesnt work at all in IE8

Google is full of this question but none of the other pages help me.

I've tried changing jquery versions, tried doing the whole var $j = jQuery.noConflict();, tried rearranging JS/jquery scripts, tried the no caching thing suggested by jquery website but still my load() doesn't work.

<a onclick="loadCont('canyou.php');">Can you help us</a>


function loadCont(file){
$j("#maincont").load(file);
alert(file);
return false;
}

As always it loads on every other browser except IE8. The alart() is there for IE8 debugging, and the file is passed successfully, its just not loaded into #maincont

Any help aboutthe code or replies appreciated. Thanks

like image 756
ben Avatar asked Aug 25 '11 16:08

ben


1 Answers

Try setting this up a little differently. Use the following code and see if you get any results.

HTML

<!-- link with ajax target in href -->
<a class="loadlink" href="canyou.php">Can you help us</a>

jQuery

<html>
<head><title>can you</title></head>
<body>
    <!-- we only want to load content from this div -->
    <div id="content">This is the only content we want returned...</div>
</body>
</html>

EDIT

If canyou.php contains a full html skeleton with <html> and <body> tags then you should have jQuery parse out only the HTML you want from that page and discard the rest (you don't want to shove <html> or <body> tags into your #maincont div). You can have jQuery do this by adding a space then a selector after the URL parameter in the load() method. Here's an example of the HTML:

<html>
<head><title>can you</title></head>
<body>

    <div id="content">
        This is the only content we want returned...
    </div>
</body>
</html>

Here's what the new load call would look like:

$('#maincont').load($(this).attr('href') + ' #content');    // Only get the content in #content div
like image 109
Joe Landsman Avatar answered Nov 24 '22 09:11

Joe Landsman