aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax - how to tell client to render new page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax - how to tell client to render new page." Watch "Ajax - how to tell client to render new page." New topic
Author

Ajax - how to tell client to render new page.

marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 176

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(),or
  • renders 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
    GenRocket Founder
    Ranch Hand

    Joined: Jul 11, 2001
    Posts: 15286
        
        6

    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.


    GenRocket - A Test Data Generation Platform
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60053
        
      65

    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?

    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    marten kay
    Ranch Hand

    Joined: Feb 03, 2007
    Posts: 176

    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Ajax - how to tell client to render new page.
     
    Similar Threads
    Printing output of loop
    some java interview Questions
    Why to use eval function inside Javascript
    Undefined on jQuery Ajax Request
    need to render tooltip with <f:selectItems> used with <h:selectOneMenu>