Strange AJAX calls


#1

Hi ,

One thing i noticed in OG is that , when the AJAX request is fired by the browser , it is returning JSON and when i try to open it from firebug as “Open as new tab” am seeing pure HTML.
More over when i do the same operation using curl , i am seeing the HTML and JSON

I need to integrate some of the AJAX calls with my UI , please let me know how i can get the JSON and not HTML

Thanks
Vineeth


#2

The RESTful requests react to the content type in the call - the Accept HTTP header
see http://blog.programmableweb.com/2011/11/18/rest-api-design-putting-the-type-in-content-type/ and http://stackoverflow.com/questions/381568/rest-content-type-should-it-be-based-on-extension-or-accept-header

You can also force the request to choose JSON by adding “.json” to the URL (before any ? query), although this is really intended for debugging. For example: http://localhost:8080/jax/portfolios.json?name=

So, the preferred solution is to send an Accept HTTP header with “application/json” as the value.


#3

Thanks @stephen .