开发者

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) {
                al开发者_开发问答ert(response);
        }
    });
});


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜