Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:54:25+00:00 2026-05-27T01:54:25+00:00

I need to send some data to a web page, ideally in json format

  • 0

I need to send some data to a web page, ideally in json format and I wonder what method is considered best, and why. Overall what good or bad experiences and surprises you had with them.

  1. <script>var myJson = <? echo json_encode($myVar);
    ?>;</script>

    advantage: the json is directly in javascript, were it will be used.
    inconvenient: <script> in the middle of html/dom is bad (js belong
    to .js files).

  2. <div data-myJson='<? echo json_encode($myVar); ?>'>

    advantage: html5 data thing is easy to work with.
    inconvenient:
    bunch of data in the dom, it doesn’t look elegant note: in my
    case, I can afford to ignore “old” browsers.

  3. ajax everything.

    advantage: the json doesn’t even need to be sent in this case, as it
    will be already available (no page change).
    inconvenient: not
    really an option as I would need to rewrite the full website.

  4. instead of sending the full json, store it in the session and send a
    key.

    advantage: less data moving around
    inconvenient: the
    data/session couple needs to be kept track of, and I like my session to be kept clean and tidy. (even if user just close the page before the flow is
    finished) (which won’t close the session).

  5. Cookies.

    advantage: herr.. is reverse evil a good thing?
    inconvenient: like session variables, but out of the cage.

  6. Store the json in the session, and ajax it when the page is loaded.

    advantage: somewhat elegant conceptually.
    inconvenient: heavy, as the ajax instruction has
    to be added to a js file, and the session has to be managed. (and
    cleansed. if the page load doesn’t finish, the json will stay until
    I cleanse it or the session finishes). Plus the html header means more bandwidth, and the we have to wait for the success to use the object.

  7. other?

edit: as there seems to be a bit of confusion, with option 3 “ajax everything” I was meaning one page load, and all content loaded by ajax, even if you go through menus, links to other pages, forms submit, and such. I consider a more traditional navigation, (pages sent by the server as new a pages), with a page doing an ajax request to retrieve some value (here, my json object) on the server, as point 4 “session”, as the main data has to remain on the server after the page has been sent to be later fetched by the ajax request. I did add option 6 for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:54:25+00:00Added an answer on May 27, 2026 at 1:54 am

    I unhesitatingly recommend #1. You want to use your data in javascript, right? #1 is the simplest way and most direct way to ensure that your data exists, as a plain-old javascript object, when the page loads. I transfer data from the server side to the browser side all the time this way and it works beautifully.

    You could arguably create better separation between your data and your UI by loading your data in an ajax call, but this is an additional http request, which will slow your page load.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to send an apex web service some data. Then name of the
From a webpage, I need to send JSON data using POST method to a
I need to send data from an IIS web server A to an Apache
I need to send some of my data into another server. Actually to post
I need to send some data from a SQL DB Server on an internal
Hi i need to post some data to a web server from windows phone
I need to send some information on a VxWorks message queue. The information to
I need to send some arguments from the iPhone to a php in the
I'm building a fairly simple PHP script that will need to send some emails
I need to implement some form of communication mechanism in my application, to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.