-3

I need to load some markers into an embedded Google Map based on what a user searches. The markers are determined by lng/lat coordinates in a MySQL table.

The map is created in a Javascript function in a separate Javascript file (so not embedded in the HTML) and it takes an XML file as input. I created a PHP page (called 'xml.php') that can dynamically generate the XML file I need based on whatever the user searchers. Right now I'm manually typing in POST information in my Javascript function, so it calls 'xml.php?query=hello'

I'd like to somehow send the original query to the Javascript file, so that I can append it to the end of 'xml.php'. This way, everything is done automatically from the original search, to generating an xml file, and reading it to create markers.

I've seen solutions that are fairly simple when the Javascript is embedded in tags but I'm trying to avoid that

Here's my function that calls for an XML file:

function downloadUrl(url, callback) {
    var request = window.ActiveXObject ?
        new ActiveXObject('Microsoft.XMLHTTP') :
        new XMLHttpRequest;

    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        request.onreadystatechange = doNothing;
        callback(request, request.status);
      }
    };

    request.open('GET', url, true);
    request.send(null);
  }

function doNothing() {}

The XML information will change based on what the user originally searched though. So it's actually a php file (xml.php) that performs an SQL search and echos it out in XML format. I can control the SQL search by adding POST info when calling xml.php

downloadURL('xml.php?query=whatever', somefunction())

But that appended POST data needs to be dynamic too. So the overall flow is:

Search page --> Sends data to results page, which calls on Javascript file to create map --> Javascript file calls on XML information to put map in results page

Nicholas Hassan
  • 949
  • 2
  • 10
  • 27
  • 4
    You're looking for AJAX. – SLaks Dec 11 '16 at 03:38
  • @SLaks I think I'm using an AJAX implementation right now. The only problem I have is that all the tutorials I've found use document.getElementByID on some kind of input box. In my example, I've already sent the form, and now the information I need to get to the Javascript file is POST in the URL – Nicholas Hassan Dec 11 '16 at 03:43

1 Answers1

0

Could show us some code?

have you tried localstorage?

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");

You can use this to set some information and then, call the post method using ajax.

but It is only useful if you want to keep some data in session.

references: [1] and [2]

Celso Agra
  • 1,389
  • 2
  • 15
  • 37
  • Hey Celso, thanks for the answer. I've added some more info about my situation. I've been trying to avoid extraneously adding values in DOM just to pull them out with the JS file. Is there a way to get the POST data from the search page directly to the JS file, which is called by the results page? – Nicholas Hassan Dec 11 '16 at 04:06
  • As I know, POST Data is only handled by server-side (http://stackoverflow.com/a/1409029/2130322). I believe there is no way to get this, unless you have some server-side code to send this to javascript. – Celso Agra Dec 11 '16 at 04:13