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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:02:54+00:00 2026-06-03T03:02:54+00:00

I am trying to fill a javascript array beaches3 from a php request dynamically

  • 0

I am trying to fill a javascript array beaches3 from a php request dynamically with a httpRequest.

var jqxhr = $.get("http://127.0.0.1/websites/map_with_me.php?region="+region+"&suburb="+suburb+"&lat="+lat+"&lon="+lng, function() {
document.getElementById("thediv").innerHTML = (jqxhr.responseText);
var beaches3 = (jqxhr.responseText);
 })

The Output of map_with_me.php is

 [
     ['Bondi Beach', -33.890542, 151.274856, 4],
     ['Coogee Beach', -33.423036, 151.259052, 5],
     ['Cronulla Beach', -34.028249, 121.157507, 3],
     ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
     ['Maroubra Beach', -33.450198, 151.259302, 1]
];

So I want to fill the beaches3 var with the dynamic positions generated by the map_with_me.php file.

if I replace the whole $.get request with the static beaches variable it works.

How do I pass the dynamic javascript generated by the php file to the javascript array?

map_with_me.php

<?php 
echo "var beaches3 = [
  ['Bondi Beach', -33.890542, 151.274856, 4],
  ['Coogee Beach', -33.423036, 151.259052, 5],
  ['Cronulla Beach', -34.028249, 121.157507, 3],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  ['Maroubra Beach', -33.450198, 151.259302, 1]
];"
?>

This works:

var jqxhr = $.get("http://127.0.0.1/websites/map_with_me.php?region="+region+"&suburb="+suburb+"&lat="+lat+"&lon="+lng, function() {
document.getElementById("thediv").innerHTML = (jqxhr.responseText);
var beaches3 = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.423036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 121.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.450198, 151.259302, 1]
    ];
 })

This Doesnt:

var jqxhr = $.get("http://127.0.0.1/websites/map_with_me.php?region="+region+"&suburb="+suburb+"&lat="+lat+"&lon="+lng, function() {
document.getElementById("thediv").innerHTML = (jqxhr.responseText);
var beaches3 = (jqxhr.responseText);
 })
  • 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-03T03:02:55+00:00Added an answer on June 3, 2026 at 3:02 am

    If you’re sure it’s an array, an not json or something else, just doing:

    $.get("/websites/map_with_me.php?region="+region+"&suburb="+suburb+"&lat="+lat+"&lon="+lng, function(data) {
        $("#thediv").html(data);
        var beaches3 = data;
    });
    

    should suffice.

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

Sidebar

Related Questions

I am trying to fill a form in a php application from a C#
I'm trying to fill an array of 20 ints with numbers from 1-20 in
I am trying to fill gridpanel to get data from database through LINQ in
I'm trying to fill an array in php with variables, but it's not working
What I'm trying to do is fill a JavaScript array with files which I
I am trying to fill in a form using Javascript/ajax/php but the problem is
I'm trying to create an iframe from JavaScript and fill it with arbitrary HTML,
I'm trying to fill some data from an xml feed we made into my
I am trying to fill my view model with some drop down options from
I'm trying to create some javascript code that will display a javascript form (from

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.