Php 点击链接,然后页面数据进入正文,url更改,聊天窗口不熄灭
早上好 我正在开发一个web应用程序,在它的左侧栏和正文中,有类似facebook的聊天模块。我的问题是当点击左侧栏的任何链接,然后页面刷新,然后聊天消失。 然后我尝试在不重定向和更改url的情况下显示页面,但ping chat消失了。我使用了nodejs进行聊天 我想点击链接,然后页面数据进入正文,url更改和聊天窗口不出去 routes.phpPhp 点击链接,然后页面数据进入正文,url更改,聊天窗口不熄灭,php,jquery,ajax,laravel-5.1,url-routing,Php,Jquery,Ajax,Laravel 5.1,Url Routing,早上好 我正在开发一个web应用程序,在它的左侧栏和正文中,有类似facebook的聊天模块。我的问题是当点击左侧栏的任何链接,然后页面刷新,然后聊天消失。 然后我尝试在不重定向和更改url的情况下显示页面,但ping chat消失了。我使用了nodejs进行聊天 我想点击链接,然后页面数据进入正文,url更改和聊天窗口不出去 routes.php Route::get('/geturl', function(){ return view('geturl'); }); <scri
Route::get('/geturl', function(){
return view('geturl');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("a[rel='tab']").click(function(e){
//code for the link action
return false;
});
});
$(function(){
$("a[rel='tab']").click(function(e){
//e.preventDefault();
//get the link location that was clicked
pageurl = $(this).attr('href');
//to get the ajax content and display in div with id 'content'
$.ajax({url:pageurl+'?rel=tab',success: function(data){
$('#content').html(data);
}});
//to change the browser URL to the given link location
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
//stop refreshing to the page given in
return false;
});
});
/* the below code is to override back button to get the ajax content without page reload*/
$(window).bind('popstate', function() {
$.ajax({url:location.pathname+'?rel=tab',success: function(data){
$('#content').html(data);
}});
});
</script>
<body>
<div id="menu">
<a href="/dashboard" rel="tab">menu1</a> |
<a href="/profile/edit" rel="tab">menu2</a> |
<a href="/contact-support" rel="tab">menu3</a>
</div>
<div id="content"></div>
</body>
geturl.blade.php
Route::get('/geturl', function(){
return view('geturl');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("a[rel='tab']").click(function(e){
//code for the link action
return false;
});
});
$(function(){
$("a[rel='tab']").click(function(e){
//e.preventDefault();
//get the link location that was clicked
pageurl = $(this).attr('href');
//to get the ajax content and display in div with id 'content'
$.ajax({url:pageurl+'?rel=tab',success: function(data){
$('#content').html(data);
}});
//to change the browser URL to the given link location
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
//stop refreshing to the page given in
return false;
});
});
/* the below code is to override back button to get the ajax content without page reload*/
$(window).bind('popstate', function() {
$.ajax({url:location.pathname+'?rel=tab',success: function(data){
$('#content').html(data);
}});
});
</script>
<body>
<div id="menu">
<a href="/dashboard" rel="tab">menu1</a> |
<a href="/profile/edit" rel="tab">menu2</a> |
<a href="/contact-support" rel="tab">menu3</a>
</div>
<div id="content"></div>
</body>
$(函数(){
$([rel='tab'])。单击(函数(e){
//链接操作的代码
返回false;
});
});
$(函数(){
$([rel='tab'])。单击(函数(e){
//e、 预防默认值();
//获取已单击的链接位置
pageurl=$(this.attr('href');
//获取ajax内容并以id为“content”的div显示
$.ajax({url:pageurl+'?rel=tab',成功:函数(数据){
$('#content').html(数据);
}});
//将浏览器URL更改为给定链接位置的步骤
如果(pageurl!=窗口位置){
window.history.pushState({path:pageurl}',,pageurl);
}
//停止刷新中给出的页面
返回false;
});
});
/*下面的代码是重写back按钮,以在不重新加载页面的情况下获取ajax内容*/
$(窗口).bind('popstate',function(){
$.ajax({url:location.pathname+'?rel=tab',success:function(data){
$('#content').html(数据);
}});
});
|
|