Это касается моего проекта в прошлом году по веб-разработке. Я хочу изменить содержимое своей страницы без перезагрузки страницы. Я знаю, что это может быть достигнуто с помощью css/ajax или jquery, но это будет только скрыть и показать или заменитьWith() в jquery. Я хочу изменить URL-адрес. я хочу достичь чего-то вроде этой страницы https://www.khanacademy.org/computing/computer-programming - когда пользователь нажимает на INTRO TO JS: рисование и анимация вы увидите URL-адрес и содержимое изменений страницы, но страница не перезагружается.Изменить URL-адрес и обновить содержимое страницы без перезагрузки
руководство будет оценено по достоинству. спасибо
небольшой проект:
**MY header.php**
<script language="javascript" src="jquery-1.4.4.min.js"></script>
<script>
$(function(){
\t $("a[rel='tab']").click(function(e){
\t \t //e.preventDefault();
\t \t /* \t
\t \t if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
\t \t if commented, html5 nonsupported browers will reload the page to the specified link.
\t \t */
\t \t
\t \t //get the link location that was clicked
\t \t pageurl = $(this).attr('href');
\t \t
\t \t //to get the ajax content and display in div with id 'content'
\t \t $.ajax({url:pageurl+'?rel=tab',success: function(data){
\t \t \t $('#content').html(data);
\t \t }});
\t \t
\t \t //to change the browser URL to 'pageurl'
\t \t if(pageurl!=window.location){
\t \t \t window.history.pushState({path:pageurl},'',pageurl); \t
\t \t }
\t \t return false;
\t });
});
/* the below code is to override back button to get the ajax content without reload*/
$(window).bind('popstate', function() {
\t $.ajax({url:location.pathname+'?rel=tab',success: function(data){
\t \t $('#content').html(data);
\t }});
});
</script>
<div id='menu'>
\t <a rel='tab' href='http://localhost/html5-history-api/menu1.php'>menu1</a> |
\t <a rel='tab' href='http://localhost/html5-history-api/menu2.php'>menu2</a> |
\t <a rel='tab' href='http://localhost/html5-history-api/menu3.php'>menu3</a></div>
мой menu1.php (menu2 и 3 имеют тот же код)
<?php
if($_GET['rel']!='tab'){
\t include 'header.php';
\t echo "<div id='content'>";
}
?>
menu1 content in menu1.php
<?php
if($_GET['rel']!='tab'){
\t echo "</div>";
\t include 'footer.php';
}?>
я хочу, когда я нажимаю на ссылку - ссылка исчезает, и он отображает только содержание, как дэ «menu1 содержание в menu1.php» только и ничего на странице
вы хотите изменить URL, и это не будет перезагружать всю страницу? –
проверьте это http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page –
Посмотрите на Angular JS и, более конкретно, на концепцию «Одностраничные приложения (SPA)». Gmail, facebook и т. Д. Все используют одну и ту же архитектуру. – AdityaParab