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 8352087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:51:52+00:00 2026-06-09T08:51:52+00:00

Using php4 how could I store an array in a hidden div so that

  • 0

Using php4 how could I store an array in a hidden div so that jquery can pick it up and then turn it into a json object? Im trying to pass an array of data to gmap so that I can load multiple markers, but cant seem to figure out how to pass a php array to jquery and then turn it into a json object.

I tried using a custom json encode class for php4 and encoding the php array to json, the problem is it spits out a bunch of garbage characters and appears to cause errors in the jquery code. Here is the array Im creating in php:

$map_array[] = array('latitude' => $result_latitude,'longitude' => $result_longitude,'html' => $result_html,'title' => $result_name,'icon' => array('image' => '/pathtoicon' .$mapi .'.png','iconsize' => array(27,27)));

$map_json = $json->encode($map_array);

Then in jquery:

    var mapcoords = $('#mapcoord').html();

        $('#rmap').gMap(
                {
                    zoom: 10,
                    markers:$.parseJSON(mapcoords)
                }

        );

When I do this, I get this error:

“SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data”

This works if I do var mapcoords = $(‘#mapcoord’).text();

The problem is, it strips out the html. So how do I pass the php array to jquery and be able to preserve the html code?

  • 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-09T08:51:54+00:00Added an answer on June 9, 2026 at 8:51 am

    Why don’t you simply create the javascript variable with php and set it there?

    For example:

    <?php
    
       $obj = "{'test': 1}";
    
        echo "<script type='text/javascript'>";
        echo "var myString = " . $obj;
        echo "</script>";
    ?>
    

    Now the variable is accessible through javascript as an object.

    If you can’t do that, you can try to convert the string into an json object using jQuery.parseJSON.

    Hope it helps!

    Did you try jQuery.parseJSON(myString)?

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

Sidebar

Related Questions

Can someone help me to setup php4 for using json? Thanks!
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
I am using php4 and jquery, I have got a php string variable $content
I would like to solve rounding mechanism by using php4,5.2 and below (not 5.3)
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I am using PHP 4, that is what the host has at the moment.
I am trying to perform a simple jQuery AJAX attempt using either a .get()
I have a file that I'm using to log IP addresses for a client.
I am using a jQuery plugin Tag-it to autocomplete the tags in the form
I'm trying to access a WebService using nuSOAP (because I'm bound to PHP4 here)

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.