I am writing a JSON response from a perl/cgi program. The header’s content type needs to be ‘application/json’. But it doesn’t seems to be recognized as response is thrown as a text file.
I would be capturing response using JSON library of jQuery. Where am I missing in sending the JSON response.
I am doing this in a perl/cgi program.
I use these in the top of my code:
Then I print the json header:
which is a content type of:
And then I print out the JSON like this:
My javascript call/handles it like this:
You don’t necessarily have to use the JSON library if you don’t want to install it, you could print straight JSON formatted text, but it makes converting perl objects to JSON prety easy.