in2code-de / ipandlanguageredirect

TYPO3 redirect - browserlanguage and ip-address based

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected token < in JSON at position 0

gvv1401 opened this issue · comments

Hello!
I have TYPO3 site (v.9.5.1) with ipandlanguageredirect (v.2.1.0). When page loaded I got error message in Chrome:

VM11063:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at XMLHttpRequest.a.onreadystatechange (Frontend.min.js?1547650834:1)

Error message in FF:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Why? Any idea?

P.S. jQuery version is 1.11.2

Please check the AJAX request in your browser console. What is the result from the server?

XHR:
http://p484107.webspaceconfig.de/?tx_ipandlanguageredirect_pi1[browserLanguage]=en&tx_ipandlanguageredirect_pi1[ipAddress]=&tx_ipandlanguageredirect_pi1[referrer]=&tx_ipandlanguageredirect_pi1[languageUid]=0&tx_ipandlanguageredirect_pi1[rootpageUid]=1&tx_ipandlanguageredirect_pi1[countryCode]=&tx_ipandlanguageredirect_pi1[domain]=
==================================================
RESPONSE HEADER:
HTTP/1.1 200 OK
Date: Thu, 17 Jan 2019 13:36:38 GMT
Server: Apache
Expires: 0
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Language: de
X-TYPO3-Parsetime: 6120ms
Last-Modified: Thu, 17 Jan 2019 13:36:38 GMT
Vary: Accept-Encoding
X-UA-Compatible: IE=edge
X-Content-Type-Options: nosniff
Keep-Alive: timeout=5, max=96
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
==================================================
RESPONSE:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<!-- 
	This website is powered by TYPO3 - inspiring people to share!
	TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
	TYPO3 is copyright 1998-2018 of Kasper Skaarhoj. Extensions are copyright of their respective owners.
	Information and contribution at https://typo3.org/
-->
....

I get the same SyntaxError message in Chrome with TYPO3 9.5.4 and EXT:ipandlanguageredirect 2.1.0.

The redirect button only has # as a link, regardless of the current website's language.

<a class="ipandlanguageredirect__button" href="#"
   data-ipandlanguageredirect-container="link">
        Zeige besser passende Version dieser Seite
</a>

That are two different things. @gvv1401 mentioned a problem on page load while @sebkln mention a problem on a click if I understand both of you.

@gvv1401 The response is simply wrong. There should no html but a JSON. Pls check the TypoScript typenum configuration (and maybe a realurl configuration).
@sebkln I would create a new issue and check the browser console for errors.

Sorry for the confusion. I do get the exact same error as @gvv1401 on page load. I just wanted to add the fact that the extension does render the suggest container1, but with a wrong (empty) link.

What I did:

  • I followed the installation routine in the README step by step.
  • I adjusted the Redirect.php to my needs.
  • As I encountered the issue described by @gvv1401, I reverted my Redirect.php to the original state, setting only the new domain.
  • I checked the response by temporarily changing JSON.parse in Frontend.min.js to console.log. Result: it's the complete HTML markup of the current page.

Environment:

  • TYPO3 v9
  • RealURL ist not installed, but a Site Configuration is used. Both frontend languages are properly set.
  • root page ID is 1 (matching default setting in Redirect.php).
  • Default language 0 is english (matching default setting in Redirect.php).
  • Language with UID 1 is german (matching default setting in Redirect.php).
  • The extension's TypoScript is loaded in its original state.

Testing

I added the frontend plugin to a test page. The result is:

{
  "redirectUri": "http:\/\/testdomain.test\/en\/tests\/",
  "activated": false,
  "events": [
    "suggest"
  ],
  "activatedReasons": {
    "differentLanguages": false,
    "differentRootpages": false
  },
  "country": "de",
  "givenParameters": {
    "browserLanguage": "",
    "referrer": "",
    "ipAddress": "127.0.0.1",
    "languageUid": 0,
    "rootpageUid": 1,
    "countryCodeOverlay": "",
    "domain": "testdomain.test"
  }
}

I assume that that I did not set every necessary configuration in Redirect.php. Can you tell me the minimal adjustments every integrator has to make?

Maybe it's an obvious mistake I made.


[1] The suggest container is hidden because of max-height: 0, which seems to be a different issue.

I'm not sure what I can answer. On one page a HTML is given back (what's wrong) and on another page the correct JSON is given back. I do not know the difference between your two instances - sorry

No problem. For now I went with a RewriteRule in my .htaccess file. Checking for browser language is sufficient in my case. Will investigate my issue with this extension at a later time.

We've got the same problem in TYPO3 9.5.
The "&type=1555" in the AJAX call is missing.

I can see this error on a Typo3 8.7.20, too.
Just as described, but I use realURL, so that does not seem to be the main reason for the error.

But I additionally I get on some pages JSON code in the browser instead of the rendere3d page (including the error in the Chrome console):
https://github.com/einpraegsam/ipandlanguageredirect/issues/20

Maybe this issue helps here

For TYPO3 9.5 you need a PageTypeEnhancer for type=1555
https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86160-PageTypeEnhancerForMappingTypeParameter.html

Just add redirect.json: 1555 to the map of your PageTypeEnhancer in the site config file.

Example:

routeEnhancers:
    PageTypeSuffix:
        type: PageType
        map:
            redirect.json: 1555

The filename of redirect.json can by anything.

In TYPO3 8.7 with realurl it should work out of the box.

Maybe @einpraegsam can adapt the docs for this issue.

Thank you for your help!
The problem is that it works in general but sometimes only the json string appears in the browser.
From then on, those pages are only reachable directly via their pageid url.

Added an example to documentation in 290f731