views:

173

answers:

3

Hi,

I am creating a .aspx page to respond to ajax requests.

If I return json back, how do I set the content type so my calling page receives the JSON properly?

I'm using jquery if that matters.

A: 

Response.ContentType = "application/json"

ZippyV
+4  A: 

I would suggest against using an ASPX page that way.

An ASMX web service or even ASHX HttpHandler would be better. When you make a call to an ASPX page, the Page class must be instantiated even if you're just using Response.Write() to output JSON. It's a lot of unnecessary overhead to add to what should be a lightweight call.

Dave Ward
These are much better approaches than an ASPX page. They sidestep the whole page model and result in snappier code.
Chris Lively
A: 

Response.ContentType = "application/text"