Reputation: 832
I have a page with an Ajax call that is supposed to replace a content div. When the link is clicked, though, the entire page is replaced with the content div, instead of it just replacing the text it was supposed to. Any thoughts?
$(document).ready(function () {
$('#gnav a').click(function () {
var page = this.hash.substr(1);
$('#contents').html("");
$('#content_wrapper').block();
$.get(page +'.php', function(gotHtml){
$('#contents').html(gotHtml);
$('#content_wrapper').unblock();
});
return false;
});
});
<div id="contents" style="height:1200px; width: 620px">
<!-- all html here that should be replaced-->
</div>
Upvotes: 0
Views: 262
Reputation: 12730
Why don't you just use $.load()?
$(function () {
$('#gnav a').click(function (e) {
e.preventDefault();
$('#contents').load(this.hash.substr(1) +'.php')
});
});
Upvotes: 2