Json or Html? How to say?
I have a controller that returns JSON or partial html depending on whether the user is logged in.
Is there a way to tell the difference after returning the result? What's the best way.
Obviously I have different actions to complete if the response is json or if it is partial html. With json, I do a redirect to the login page, and with html, I just display it. If only I could render the html server and send it back in json format? From what I've heard, this still cannot be done. Thoughts?
Greetings.
DUPLICATE: Can I evaluate the response type of the $ .ajax () call on a successful callback?
source to share
You can use JSON.js to find out if a given string is JSON or not.
JSON encoder / decoder
This object uses good techniques to quickly encode / decode all types of JSON-compliant variables and is slightly more secure.
It provides a function decode()
that returns either an object or undefined
.
source to share