Andreas Bonini
Andreas Bonini

Reputation: 44752

Replacing the contents of an entire webpage through ajax

I'm aware that this is kinda a hack but for reasons of simplicity I would like to replace the contents of an entire webpage with an answer received through Ajax. This includes possible HTTP headers. Is it possible to do so?

To clarify further, right now I added for debugging purposes:

alert(response);

and this produces:

example http://img195.imageshack.us/img195/6362/testbzi.png

For reasons I don't wanna get into I cannot do something like location.href = 'ajax_page'. Solutions that use jQuery would be better.

Code used to obtain the data:

$(document).ready(function() {
    new AjaxUpload('#upload', {
        action: '/AjaxSubmit',
        name: 'file',
        autoSubmit: true,
        onSubmit: function(file, extension) { return true; },
        onComplete: function(file, response) {
                alert(response);
        }
    });
});

Upvotes: 0

Views: 223

Answers (4)

Ms2ger
Ms2ger

Reputation: 15983

I'd use <a href=""></a>.

Upvotes: 0

BalusC
BalusC

Reputation: 1108742

The server has to take the following two things into account:

  • Write it as UTF-8.
  • Set Content-Type response header to text/html;charset=UTF-8.

Upvotes: 0

Roland Bouman
Roland Bouman

Reputation: 31961

I don't think you can, not with HTTP headers. The reason is that the scope you have control over, the document, is created and rendered after the data is received.

Most of the HTTP headers affect the way data is transported and received. For example, by the time you get your hands on the response, it has already been uncompressed, character encoding has been applied etc.

Upvotes: 1

SLaks
SLaks

Reputation: 887451

I'm not sure what you mean by including HTTP headers.

From your screenshot, it looks like your server isn't setting the encoding correctly.

Solving this will depend on the page you're requesting and the web server you're using.

You should try requesting the URL in a new tab and/or in Fiddler, and you shouldn't debug it in the AJAX call until you can get the correct content in a browser tab.

Upvotes: 0

Related Questions