简体   繁体   English

TYPO3(v9.5)使用Ajax加载新闻扩展

[英]TYPO3 (v9.5) News extension load with Ajax

I would like to load the Details view of a news list via Ajax. 我想通过Ajax加载新闻列表的Details视图。 The page reload is not a good UX - would be better for the old detail to fade out while the list stays in place on the left (or wherever) and just the detail view of the article change. 重新加载页面不是一个好的UX-当列表保留在左侧(或任何位置)并且仅更改文章的详细信息视图时,旧的详细信息会逐渐消失。

Problems: 问题:

  • SEO might break SEO可能会中断
  • Unique URLS for an article might be a problem without extending News 如果不扩展新闻,则文章的唯一URL可能会成为问题。

I am trying to get this to work: https://gist.github.com/markhowellsmead/98de3dbaaec2faf52e0863907b5e403e 我正在尝试使其工作: https : //gist.github.com/markhowellsmead/98de3dbaaec2faf52e0863907b5e403e

also looking at: http://unterricht.lacheiner.net/index.php?id=217 Which is an example of loading more News List Items 还查看: http : //unterricht.lacheiner.net/index.php?id=217这是加载更多新闻列表项的示例

I am also looking at getting the full detail URL and use that to load the detail from a page with a unique detail only template as www.example.com/?type=9999 that only has the detail 我也正在寻找完整的详细信息URL,并使用它来从具有唯一详细信息模板的页面加载详细信息,如www.example.com/?type=9999,其中仅包含详细信息

lastly looking at URL Routing http://www.softfinity.com/blog/an-simple-introduction-to-url-routing/ 最后查看网址路由http://www.softfinity.com/blog/an-simple-introduction-to-url-routing/

I would not recommend this, as this will break default browser behavior like back and forward, will make it hard to link directly to a news item, etc. But if you really want to do this, I would do this by adding an click event to the a-tag for the link to the detail page in the list view, get the URL, fetch the detail page using ajax, then only get the part of the page I want and display it. 我不建议这样做,因为这会破坏默认的浏览器行为,例如来回移动,将使其很难直接链接到新闻项,等等。但是,如果您确实要这样做,我可以通过添加click事件来实现。到指向列表视图中的详细信息页面的链接的a-tag,获取URL,使用ajax获取详细信息页面,然后仅获取所需的页面部分并显示它。

For example (using jQuery): 例如(使用jQuery):

$('div.newsList div.item a').click(function() {
    doStuffToShowItsLoading();

    //
    $.ajax(this.href, {
        dataType: 'html',
        success: function(jqXHR, textStatus) {
            var detailHtml = $(jqXHR.responseText).find('div.newsDetails');
            $('div.newsDetail').html(detailHtml);

            doStuffToStopShowingItsLoading();
        },
        error: function() {
            alert('Something went wrong');
        }
    });
    return false;
});

That way, the links can still be followed by search engines or people who have JavaScript disabled. 这样,搜索引擎或禁用JavaScript的人仍然可以跟踪链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM