[英]Remove appended # from url in ajax call
In my rails application(rails 2.3.4 and ruby 1.8.7) When i click on News , an ajax call is made and data is loaded. 在我的rails应用程序中(rails 2.3.4和ruby 1.8.7),当我单击News时,将进行ajax调用并加载数据。
<a href="News" onclick="load_feed();"><u>Show More...</u></a>
<script>
function load_feed()
{
$.ajax({
url: this.url,
dataType: 'script'
})
$('div .rss_feed_1').append("<%= escape_javascript(render :partial => "news_feed_data") %>");
}
</script>
When i click an ajax call is made and data is loaded. 当我单击ajax调用并加载数据时。 but the url changes to
但网址更改为
http://localhost:3000/us/dropbox#News from http://localhost:3000/us/dropbox , Is there any way out that i can get this url http://localhost:3000/us/dropbox/News by removing the #. http:// localhost:3000 / us / dropbox#News from http:// localhost:3000 / us / dropbox ,有没有办法让我获得此网址http:// localhost:3000 / us / dropbox / News通过删除#。
Using the new Javascript pushState you can create pretty looking URL:s while staying on the same page and only using AJAX for data fetching. 使用新的Javascript pushState,您可以在外观相同的页面上创建漂亮的URL :,并且仅使用AJAX进行数据提取。
Here is an example of it. 这是一个例子 。 This is also the method Facebook uses.
这也是Facebook使用的方法。
You just have to put 'return false;' 您只需要输入“ return false”即可; at the end of your function or write 'onclick="load_feed(); return false;"'.
在函数末尾,或写“ onclick =“ load_feed(); return false;””。 So you prevent that the default action (following the link) will be triggered.
因此,您可以防止触发默认操作(跟随链接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.