0

I am building a WebGIS website and I faced with some problems. First of all I have an HTML file, where I use LeafLet map-visualizer. Every time when an user "pan" on the map, the boundary of the map should be sent to a PHP file, where I query the new informations from the Postgresql-PostGIS database server then generate XML file from them. After this procedure I would like to use the XML file to visualize the datas on my HTML file using Leaflet. Therefore I would like to know what kind of strategy would you advise me in this situation.

So far I have successfully done the following things:

  • I have a index.html file, where I have put the Leaflet map. With some Leaflet function I could get the datas of the boundary box, so the only thing what I need is to send it to the PHP file which is called dbAccessAndXmlGenerator.php . Shall I use AJAX here?

  • At the beginning of the project I successfully implemented to get the datas from the XML file and visualize it on the map. I used this implementation:

    $(document).ready(function()
    {
    $.ajax({
        type: "GET",
        url: "xmlRes.xml",
        dataType: "xml",
        success: parseXml
    });
    

Then there is a parseXML javascript function, where I can use the datas from the xml file:

    function parseXml(xml){...}
  • The query and the xml generation in the dbAccessAndXmlGenerator.php works properly.

In the html file there is a javascript function called onMapChange(e) which can produce thes data of the boundary box of the map every time when an user panning or moving on the map. So my task would be to send these variables to the PHP file, where I would make the query using these variables, then the PHP file would generate an XML which would be used by the HTML and javascript again.

I hope I was understandable. I am still beginner of using all of these languages together, so sorry for it. Thanks in advance!

Best wishes

Daniel

1
  • I am confused how to solve put the everything together. My question would be: what kind of solution should I use to send the the variables from javascript to the php. Links or some information would be very nice, and i would appreciate them. My second question is: how can I achive that I wait until the php file generates the xml, then I use it from a javascript in my html. Thanks for spending time for my problem! Commented Jan 20, 2015 at 16:14

1 Answer 1

1

All you need is:

$.ajax({
    type: "POST",
    url: "some_script.php",
    data: { "parameter1" : 1, "parameter2" : 2 },
    dataType: "xml",
    success: parseXml
});

And in some_script.php :

$parameter1 = $_POST['parameter1'];
$parameter2 = $_POST['parameter2'];
...
// generate XML and echo it

No need to change the parseXml() function, it will work just fine

Sign up to request clarification or add additional context in comments.

6 Comments

Hey Oleg Dubas! Thanks for the fast reply! I'm trying to solve the task using your advise, but still I don't get something. How can I refer the elements of the xml which is parsed? I would also like to have one more question if it is possible. Where should I put the $.ajax({...}); ajax call? If I am not mistaken, in the "onMapChange(e)" function which is called every time when an user move or pan on the map. I really appreciate your help, Thanks so much! Have a nice day!
@mirind4, first of all — yes, $.ajax call you should put in that function. If you put it just in $(document).ready — it will run at the very start, and I don't think this is what you want. As for XML elements accessed — I didn't see the code, I don't know how to access them, all you shown us is the function header function parseXml(xml){...}. And maybe you need JSON instead of XML? JSON is native to Javascript and very easy to access and traverse
I successfully done with XML. Thaaanks so much! ;) Next time I may use JSON instead :) I still would like to have question if no problem. Before this implementation I used XMLHttpRequest() function for getting the datas from the xml. Is it also AJAX? I have looked for it on the internet, and as far as I know, it is also AJAX.
Yes , this is the bare AJAX :) jQuery is much more convenient and cross-browser.
Thanks a lot Oleg Dubas! I love this site because people like you, so helpfull, and last but not least very skilled at programming topics!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.