Include AJAX-fetched data in page title?
See original GitHub issue/
: Products listing. Clicking on a product takes you to for instance/product/12
./product/:id
: Product detail page.
On the start page I want the page title (document.title
) to be: “MyStore”. Easy enough.
On the product page the page title should be for instance: “Rolex watch – Mystore”. When this page is entered, I fetch the product details with AJAX (from /api/v1/products/12
for instance). When the request is done I have access to the product name (“Rolex watch”) and want to put that in the page title. However, redux-first-router seems to only update the page title when the current location changes, not when arbitrary state updates.
Am I missing something?
Just tell me if you need more details 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to use ajax to get page title for a URL
1 Answer 1 ... var matches = html.match(/(.*?)</title>/);. in your request function . and put,. dataType: "html",. in your ajax request .
Read more >How do I add meta data and a page title through ajax?
somewhere in your JavaScript. A good place to do this in regards to the tutorial script you're using would be inside the ajaxLoad()...
Read more >Fetching Data with AJAX and Django
An AJAX request made with fetch will include several headers. We expect the data returned from the view in JSON form, so we...
Read more >Getting <title> tag from HTML page using $.ajax()
I am using $.ajax() to pull the page and process the <title> tag from the response $(data). For some reason, Opera is able...
Read more >Using the Fetch API - MDN Web Docs
The fetch specification differs from jQuery.ajax() in the following ... body data type must match "Content-Type" header }); return ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s the most common use case and all many people need
that’s a fine solution. you can also set
document.title
manually any time you want on the client, if you want to avoid a large dependency just for a one liner. …for SSR, it’s just a matter of grabbingstate.title
and putting it in the HTML you spit out. since this isn’t dependent on RFR updating the browser’sdocument.title
when used on the server,state.title
will work fine. Essentially you’re using Helmet now just for the client side aspect.Here’s another way you might like:
that way it still works as expected on the server, and on the client you update the title on every single title change automatically. no extra libs needed. very few extra lines of code.