| Author |
Ajax - how to tell client to render new page.
|
marten kay
Ranch Hand
Joined: Feb 03, 2007
Posts: 168
|
|
Hi
I am creating a web interface for an app with these steps:
1. Server generates HTML doc, tracking the id of active elements in a map
2. When the user clicks an active element, the client sends a XMLHttpRequest with the id to the server
3. Server generates a response using the map and other info, sends back to the client either a
javascript function in a string, or a new HTML doc for rendering
4. the client then
executes the javascript using eval(),orrenders the new page (how do I do this?)
Question: How to get the client to render the new page when it's expecting a XMLHttpResponse?
Other Question: Is this OK to do, or is this an evil use of eval?
|
when in doubt put it in parenthesis and stick a dollar sign in front of it, only good can come from this.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
You would need to put something in the response that your JavaScript code looks for and decides to render a new page, probably using the window.location. And no, running JavaScript pulled from the server is quite common.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
The whole point of Ajax is to not render a new page. How about, instead of returning the HTML for the new page, it returns the URL to the new page, and you do a JavaScript redirect to that page?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
marten kay
Ranch Hand
Joined: Feb 03, 2007
Posts: 168
|
|
Cool, thanks to both; this has really helped to clean up my code.
Been reading too much Crockford scaring my on the eval thing. But generating javascript on the server sure is neater.
Now i'm returning the following to the client when a new document is required:
and this works in both firefox and IE.
FYI - This page works a table (changing details, adding/deleting rows etc) where most can be done with ajax, but when a different view is required (different rows), I need to render the new page, so that is where this comes in. Although I am cheating a bit as I am sorting on the server which perhaps I shouldn't.
|
 |
 |
|
|
subject: Ajax - how to tell client to render new page.
|
|
|