开发者

Remove appended # from url in ajax call

开发者 https://www.devze.com 2023-04-12 09:36 出处:网络
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.

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.

 <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. but the url changes to

开发者_Go百科

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 #.


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.

Here is an example of it. This is also the method Facebook uses.


You just have to put 'return false;' at the end of your function or write 'onclick="load_feed(); return false;"'. So you prevent that the default action (following the link) will be triggered.

0

精彩评论

暂无评论...
验证码 换一张
取 消