Подгрузка контента в определенный <div> (При помощи Ajax)
При нажатии на ссылку подгружается контент из другой страницы при помощи Ajax.
Вот HTML разметка:
Javascript код:
$(document).ready(function() {
$('#get_content').click(function() {
$.ajax({
url: 'pages/page1.php',
cache: false,
beforeSend: function() { $('#content').html('Please wait...'); },
success: function(html) { $('#content').html(html); }
)};
)};
)};
$('#get_content').click(function() {
$.ajax({
url: 'pages/page1.php',
cache: false,
beforeSend: function() { $('#content').html('Please wait...'); },
success: function(html) { $('#content').html(html); }
)};
)};
)};
Если вам необходимо сделать более одной страницы, то проще написать функцию:
<script type="text/javascript">
function loadContent(urlToload, container) {
$.ajax({
url: urlToload,
cache: false,
beforeSend: function() { $(container).html('Loading content, please wait...'); },
success: function(html) { $(container).hide(); $(container).html(html); $(container).show('slow'); }
});
}
</script>
function loadContent(urlToload, container) {
$.ajax({
url: urlToload,
cache: false,
beforeSend: function() { $(container).html('Loading content, please wait...'); },
success: function(html) { $(container).hide(); $(container).html(html); $(container).show('slow'); }
});
}
</script>
- Categories:
- heihachi's blog
- Add new comment
- 1020 reads

Recent comments
5 hours 33 min ago
8 hours 25 min ago
1 day 10 hours ago
1 day 17 hours ago
4 days 2 hours ago
4 days 2 hours ago
2 weeks 1 day ago
3 weeks 7 hours ago
4 weeks 2 days ago
7 weeks 5 days ago