views:

142

answers:

3

Hello,

I'm using jquery's $.post like this:

$.post("/searchresult", $("#searchDiv").serialize(), function(data) { //??? });

The "data" parameter has all the html code of the result page I want.

The question is how do I replace my current page's content with this one returned by the $.post function.

Thanks,

Rui

A: 

I've done this with multiple ajax calls to refill a page using $('body').empty() and then several $('body').appendTo(...)

Assuming you can arrange for your webservice to return innerHtml of body alone (and not an entire html document), I think just $('body').html(data) should work. if not, i would consider loading the body with an IFRAME that src's that url.. or similar

Scott Evernden
+2  A: 

$('body').html(data); should do it.

Matěj Grabovský
I've tried this earlier, but the result of the post is an entire page and not only the body part. I've no control over the result, since this is a call to a third party code.
Rui
Them maybe try something like `$('html').html(data);`.
Matěj Grabovský
+1  A: 

You can use:

$('body').load("/searchresult", { data : $("#searchDiv").serialize() }, callBackFunction);
Cesar