Google is full of this question but none of the other pages help me.
I've tried changing jquery versions, tried doing the whol开发者_StackOverflow社区e 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
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
Yo Bro. You forgot e.preventDefault();
If you want to have a link open up in a div on your current page, for ex:
<a class="loadlink" href="canyou.php">Can you help us</a>
Your jQuery should look like this::
$("a.loadlink").click(function(e){
e.preventDefault(); //this prevents the redirect that the <a> tag makes on default
// then enter the rest of your jQuery here:
var file = $(this).attr("href");
$("#maincont").load(file);
});
That should work 'plug-n-play'.
the letter j
between $
and (.
is it normal ?
is it not $("#maincont").load(file);
I use load with IE8... it works good personally
精彩评论