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
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Send JSON Data With Page Response

  • 11-07-2014 4:56pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,029 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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