Here's the scenario:
I want to make some HTTP API calls using Javascript, and have the response load in the browser. The requests might be GET, POST, PUT or DELETE, and the response that comes back could be any type of content - it might be HTML, JSON, XML, or an images, document, binary content, or whatever. I'd like the response to be handled by the browser in exactly the same way as it would if the browser was loading a new page.
The problem is that I can't see any way to load the arbitrary content that I receive.
Obviously it's possible to load content into the DOM, but that only allows me to deal with HTML. (And potentially embedding some media types such as Images etc.) I don't see any obvious way to deal with embedding response types such as JSON and XML without having to construct special cases for how to renderer each type into HTML.
I've considered if there might be some work around involving frames or changing window.location to load the content, but I can't see any way to make it work.
Is it at all possible to do what I'm looking for, or can you suggest any elegant workarounds that might help?
Edit:
For a bit more background - This is for some work on an API browser. I've no problem doing what I need with GET and POST - it's PUT and DELETE that are awkward, since I can't support them directly with HTML. At the moment the implementation uses some server-side trickery and a hidden _method field on the form, that allows POST requests to be overloaded into PUT/DELETE/OPTIONS/whatever, but ideally I'd like to take that logic out of the server side, and do the equivalent using javascript.
Right now I don't think it's actually do-able, but I'm hoping that someone can prove me wrong, or find an elegant work-around.
GETrequests.I'd like the response to be handled by the browser in exactly the same way as it would if the browser was loading a new page.Then load a new page. Your browser already has this functionality.GETrequest (orPOST, for a POSTed form), which isn't sufficient for what I want. I want to also be able to load a new page in response toPUTandDELETErequests.