开发者

Present XMLHTTPRequest Response to the Client?

I am using an XMLHTTPRequest to fake a RESTful interface. After the response object returns data from the request, how can i present that to the user? For example, in a PUT request, the server actually responds with a full HTML page of data (in most cases), and i want to display this whole page to the client. Any idea how? I'm sure there is an answer out there, but my lack of JS knowledge has me running into a wall, probably due to poor JS terminology.

Note that i am not more than willing to use a modern JS suite such as DOJO or JQuery. Also, i am not really looking for an Ajax like effect. In fact, once a couple browsers support the proper HTML5 spec form methods (GET/POST/PUT/DELETE) i'll be dumping this JS hack for it.

Any help would be mu开发者_运维问答ch appreciated!

Edit: Talking with others, two ideas were presented. One was to use an IFrame and shove the data in there. The other was to redirect to "data:text/html,"+xhr.responseText, which works, but is ugly to the user. :/.. i may end up just giving up and hiding method arguments in the HTML Form (hidden input) and dealing with it server side because i simply have yet to see a good way to use JS to implement client side support for a RESTful interface.


You can open a pop-up container and write all your response to that container or you can open a new window using javascript and put all the response data to that window.

for e.g. :

function writeConsole(content) {
  top.consoleRef=window.open('','myconsole',
  'width=350,height=250'
  +',menubar=0'
  +',toolbar=1'
  +',status=0'
  +',scrollbars=1'
  +',resizable=1')
  top.consoleRef.document.writeln(
  '<html><head><title>Console</title></head>'
  +'<body bgcolor=white onLoad="self.focus()">'
  +content
  +'</body></html>'  )
  top.consoleRef.document.close()
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜