2015-03-03 51 views
0

我有一个页面,通过ajax从其他文件获取内容,它工作得很好,但是当通过地址栏导航时,它不起作用,因为事件只在点击时触发。我搜查了,但我找不到适合我需要的解决方案。我已经给了我的代码。有人帮忙。ajax内容的URL导航

<a href="#profile" onclick="profile()">Profile</a> 
<div id="home-content" class="container-fluid"></div> 

<script> 
function profile(){ 
    $.ajax({ 
     type: "POST", 
     url: "functions.php", 
    data: {action:profile}, 
     success: function(response) 
     { 
      $('#home-content').html(response); 
     } 
    }); 
} 
</script> 

所有我想要的是,当我像家/#的个人资料,个人资料页已经被加载输入地址,也应该是可导航的,与“个人资料”网页历史记录条目

+0

工作只有在的onclick ...具有因您使用的onclick事件仅 – Arun 2015-03-03 04:56:31

+0

不然。在身体的onload调用函数<正文onload =“profile()”> – Arun 2015-03-03 04:58:03

回答

0

请使用此功能

<body onload="profile()"> 

和ONCLICK funtion删除

+0

感谢您的回复,但这不是问题。我需要的是内容 – 2015-03-03 05:00:49

+0

的url导航,你想通过url直接访问ajax内容? – Arun 2015-03-03 05:01:38

+0

是的,就像twitter一样 – 2015-03-03 05:04:16