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

  • SEARCH
  • Home
  • 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 8304985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:58:44+00:00 2026-06-08T17:58:44+00:00

EDIT: SOLVED. Use any of the solutions below, but document.onload needs to be changed

  • 0

EDIT: SOLVED. Use any of the solutions below, but document.onload needs to be changed to window.onload. Also works without needing window.onload function anyway.

Here is the test.php file that i’m working with

<?php 
  include("conn.php");
?>

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>

    <script src="js/jquery.js"></script>
    <script type="text/javascript">
        document.onload = function (){
          var jsonString = '<?php echo json_encode($rowarr); ?>';
          var jsonObj = jQuery.parseJSON( jsonString );
          console.log(jsonObj);
          alert( jsonObj.Auckland );
    };

  </script>
</body>
</html>

I have verified in Chrome Developer tools the value of jsonString to be

'{"Auckland":37616,"Wellington":35357,"Christchurch":29818}'

After that I don’t get any log on the console or any alert box. I have also tried JSON.parse method instead of jQuery.parseJSON to no avail.

I’m trying to get this JSON into a datatable format used for google charts geo chart which looks like this bit of code

var data = google.visualization.arrayToDataTable([
    ['City',   'Population', 'Area'],
    ['Rome',      2761477,    1285.31],
    ['Milan',     1324110,    181.76],
    ['Naples',    959574,     117.27],
    ['Turin',     907563,     130.17],
    ['Palermo',   655875,     158.9],
    ['Genoa',     607906,     243.60],
    ['Bologna',   380181,     140.7],
    ['Florence',  371282,     102.41],
    ['Fiumicino', 67370,      213.44],
    ['Anzio',     52192,      43.43],
    ['Ciampino',  38262,      11]
  ]);
  • 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-06-08T17:58:45+00:00Added an answer on June 8, 2026 at 5:58 pm

    If you don’t put it as a string it would be an object and you would not have to parse it

    var jsonObj = <?php echo json_encode($rowarr); ?>;
    

    instead of

    var jsonString = '<?php echo json_encode($rowarr); ?>';
    var jsonObj = jQuery.parseJSON( jsonString );
    

    It looks like document.onload doesn’t fire/already fired? you should use window.onload or $(document).ready() instead.

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

Sidebar

Related Questions

EDIT: solved it, turns out I should use %c not %s because foodSelect and
EDIT: solved, look below for my solution. first of all, this is my very
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Edit: [Solved] : It seems that the getTableCellRendererComponent of the CustomTableCellRenderer is called every
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
edit: Solved - mod_rewrite was the problem I can't get CI to work as
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
edit This question is solved! Having something weird. I'm using html { font-size: 100%

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.