I have a Ajax call who render a page in a controller and return the result.
But I can’t figure out how to render that page in place of the current one from the Ajax call.
If you are returning HTML markup from your ajax call, you can also set “dataType” to “html”. No need to json encode it.
As emuthomi said, in the controller just return your html code.
In your success callback, just use the “result” variable.
I don’t think replacing all the content is the is a good practice.
You may end up removing some script tags generated by the framework near the closing tag.
Unless it’s a really simple results page or something like that.
Create a div inside the , give it some id and put the contents in it.
But I need to replace all content of the page since it’s a new page.
The Ajax takes a screen shot, send it to the server and the server return to a contact form with the file ready to send after the user completed the rest of the form.
So I just called window.location.href = “/index.php?r=site%2Fcontact” after Ajax return.
Easier and faster.