Skip to content Skip to sidebar Skip to footer

Document.write In Jsonp Callback

I am making a cross domain request using script tag hack and jsonp. In the callback function, I want to write the data received to DOM using document.write(). I know that I should

Solution 1:

You should note that document.write(); calls an implicit document.open();, thus, in effect, clearing everything you have had in the document so far. It is impossible to add content to a document using document.write();. It is, however, possible to use document.write(); to write an entire document.

You have several possible solutions:

  • You can pass the target element as a GET parameter, as @kirilloid noted.
  • You can insert an IFrame object at the desired place, and use myIFrame.document.write(); to update its content.

This is basically happening because you are updating the content of a container that is the parent to your script code, and as such, is not closed yet.

Either that, or I'm entirely off track here which, let's face it, is entirely possible. ;-)


Post a Comment for "Document.write In Jsonp Callback"