Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Send JSON Data With Page Response

Options
  • 11-07-2014 4:56pm
    #1
    Registered Users Posts: 2,815 ✭✭✭


    This might be an obvious question but here goes.

    I know how to implement a standard page request-response using Java (standard servlets or with Spring). I also know how to retrieve data from the server using AJAX, JSON and Javascript.

    For example, I know how to do this:

    - User requests a page
    - User selects an item from a dropdown list
    - A DIV is updated using AJAX with information from the server based on the item selected

    However, I’m unsure how to store data in JSON / JS with the actual page response. For example:

    - User requests a page
    - User selects an item from a dropdown list
    - A DIV is updated using data already contained within an existing JSON structure that was sent with the initial page response. An additional server request is not made.


    Firstly, I don’t even know if this is possible without doing a second server request. Secondly, if it is possible, how it is done?


Comments

  • Registered Users Posts: 2,022 ✭✭✭Colonel Panic


    If you are generating the page dynamically, why can't you put the JSON into a javascript variable when the page is built by the controller?

    That said, I would probably just get the data in a 2nd request on client side load and not really worry about it too much.


  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    That said, I would probably just get the data in a 2nd request on client side load and not really worry about it too much.

    Far simpler and tidier


  • Registered Users Posts: 2,815 ✭✭✭SimonTemplar


    If you are generating the page dynamically, why can't you put the JSON into a javascript variable when the page is built by the controller?

    That said, I would probably just get the data in a 2nd request on client side load and not really worry about it too much.

    Maybe I'm a little native about the number of server requests for a page. According to Firebug, the ryanair homepage makes 79 requests for different resources (images, js files, CSS, etc). I foolishly assumed all that was sent in one response.

    If that is the case, another request for JSON data doesn't seem too bad.


  • Registered Users Posts: 39 Meritor


    Its always better to send another request to get data for better UI experience rather than worrying about cost of another request made from client.
    If you get all the data in very first request it definitely will take time for page to load. So, by the time User watches the loaded page and ready for another action, another request would have brought the data from server.


Advertisement