in2code-de / ipandlanguageredirect

TYPO3 redirect - browserlanguage and ip-address based
GNU General Public License v3.0
14 stars 14 forks source link

Unexpected token < in JSON at position 0 #13

Closed gvv1401 closed 4 years ago

gvv1401 commented 5 years ago

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

einpraegsam commented 5 years ago

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

gvv1401 commented 5 years ago
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/
-->
....
sebkln commented 5 years ago

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>
einpraegsam commented 5 years ago

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.

sebkln commented 5 years ago

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:

Environment:

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.

einpraegsam commented 5 years ago

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

sebkln commented 5 years ago

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.

No5251 commented 5 years ago

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

hilburger commented 5 years ago

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

Patta commented 5 years ago

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.

hilburger commented 5 years ago

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.

einpraegsam commented 4 years ago

Added an example to documentation in 290f731fb2fde08cf0970e7864d0e08922bb2100