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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:54:52+00:00 2026-06-15T12:54:52+00:00

I’m using a map plugin to render some data. The data comes from the

  • 0

I’m using a map plugin to render some data. The data comes from the DB and into a json file – the script works great. I decided to use the data directly from the php output instead of making a json file. For some reason the javaScript doesn’t accept the direct php input. I’m using codeigniter MVC

Here is the sample code that currently works:

$.getJSON('_data/index/data.json', function(data){ ...

Here is what I tried:

 var dataMap = '<? print $mapData;?>';
        $.getJSON(dataMap, function(data){...

* EDIT 2 *

Based on the answers – this option doesn’t work either.

var dataMap = '<?php echo $mapData;?>';
        $.get(dataMap, function(data){...

And here is the json data

{"countries":{"AL":"1","GB":"1","RS":"1","BG":"6","CA":"3","AT":"2","CD":"1"}}

EDIT

$mapData is

FOREACH LOOP
 $retdata['countries'][] = strtoupper($row->code);
 $retdata['num'][] = $row->num;
ENDFOREACH LOOP
 $retdata['countries'] = array_combine($retdat['code'], $retdata['num']);
 $retdata = json_encode($retdata);

And then it is printed into a file as normal. This is into the model, then I pass it to the controller and then into the view. The string is the same in the $dataMap that I have on file and the one that is being sent to the view.

  • 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-15T12:54:52+00:00Added an answer on June 15, 2026 at 12:54 pm

    If you are just going to directly insert your JSON data into a javascript variable (rather than using AJAX), then you shouldn’t need a getJSON call at all. Just write the object directly like this.

    var js_object = <?php echo $mapData; ?>;
    alert(js_object.countries.AL);
    alert(js_object.countries.GB);
    

    Note that the PHP string is not echoed into enclosing quotes, this means you are directly creating a javascript object literal, not a string that then needs to be parsed into an object via JSON.parse()

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,

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.