0
votes

we are working on implementing amp pages for our site.We are using AEM cms,we followed the selector approach to identify the amp specefic resource scripts to render the content But while using json data and amp-list we are getting Status Code:302 Found and error in console Error fetching amp-list: Unexpected token < in JSON at position 1​​​

We tried using the same samples given in amp documentation and still ending up with the same exception

Note : While directly hitting the JSON from browser we are getting the response. I have added the required scripts for amp-list and template in header part

Any thoughts/suggestions will be of great help

Code snippets

Amp Page for the component

<amp-list width="auto"
  height="100"
  layout="fixed-height"
  src="http://localhost:4502/xxxxx/results.json"
         <template type="amp-mustache"
                    id="amp-template-id">
              <li>
                  <a href={{url}}>{{title}}</a>
              </li>
          </template>
</amp-list>

results.json

{
 "items": [
   {
     "title": "amp-carousel",
     "url": "https://ampbyexample.com/components/amp-carousel"
   },
   {
     "title": "amp-img",
     "url": "https://ampbyexample.com/components/amp-img"
   },
   {
     "title": "amp-ad",
     "url": "https://ampbyexample.com/components/amp-ad"
   },
   {
     "title": "amp-accordion",
     "url": "https://ampbyexample.com/components/amp-accordion"
   }
 ]
}
1
Preview the actual request the browser is making when you open the page. If there's a < character, there's a good chance you're getting an HTML response instead of a JSON for some reason. Check what the response body and the status code are.toniedzwiedz
it's hard to offer advice without seeing the page. the code above is error free, so your error is not visible to folks that may be able to help. @toniedzwiedz has a good imagination - and may be right - but the rest of us can't guess at the source of the problem.Jay Gray

1 Answers

0
votes

Amp will not send cookies with the request (login tokens) resulting in 302 code

Notice the network tab. Every call is followed by a second ajax trying to get login token.

Try using the same on publish mode as anonymous user. If anonymous user is given read permission to the node you are reading, you should get a 200