Getting <anonymous> as JSON response


(Serge) #1

Any idea why I’m not getting a JSON response back from the server?

PS: Don’t mind the console.print typo in the screenshot here, that’s not the issue :wink:


(Mahearnpad) #2

Have you set the page that’s getting the json response to the appropriate MIME type?

e.g. you need to have your page encoded like this:

<MySource_PRINT id_name="__global__" var="content_type" content_type="application/json" />
<MySource_AREA id_name="content_body" design_area="body" />

(Serge) #3

The web page that is making the JS API call has to be of type application/json??? How does that make any sense?

  1. Web pages (content type text/html) can make JS API calls.
  2. I’m not loading a JS file, I’m making an API call using the Squiz Matrix JS API, this stuff should work out of the box.

Must be a permission issue or something the like – “anonymous” … sounds like a lack of credentials compounded with a very bad error management. Any idea?


(Mahearnpad) #4

Sorry, misundertood your intention. It’s when I saw the error “unexpected token <” that lead me to come to this conclusion.


(Bart Banda) #5

Looks like you haven’t set a root node on the details screen of the JS API? The red text in your screenshot. This is basically to control what areas of the system the JS API should have access to. Try setting that to 1 and see if that fixes it?

Also, check the network tab in Chrome when you do the JS API call to see what the raw response of the AJAX call is.


(Serge) #6

Not sure what’s going on but looks like the object is making the Ajax request to the wrong endpoint (a web page instead of the JS API backend interface / endpoint). And root node thingy has been set to 1 (/)


(Bart Banda) #7

Ok, so I think we need to go back to the fact that the JS API asset doesn’t have a proper URL on it.
What you need to do is to put it under a site asset somewhere so that it gets a full URL on its web path screen.
Basically so that it can inherit a web path from its parent.
This can either be your main site, or another dedicated site asset where you house all of your other file assets such as CSS, JS, Images etc…


(Serge) #8

Seems to be working, I’m getting objects now. Cheers :slight_smile: