0

I have a web app that creates a JSON. Also I have a python app that reads in JSON. Right now I am only able to use console.log to see the JSON. This functions returns my JSON:

map.on('draw:created', function (e) {
    var geojsonFeature = e.layer.toGeoJSON();
    console.log(geojsonFeature);

How can I send this JSON to my Python app. Is Flask a good option to do that?

enter link description here

ustroetz
  • 5,802
  • 16
  • 47
  • 74

2 Answers2

0

It's worth looking at this very popular question on using jquery to serialise JSON to then send to your server (so that flask can read it).

You can then use the jquery $.ajax() function (documentation) to POST your data.

$.ajax({
type: "POST",
url: "http://path.to.yourserver.com/",
data: "{your: data}"
})

There's also some documentation on using jquery for AJAX requests in the flask documentation.

Community
  • 1
  • 1
Ewan
  • 14,592
  • 6
  • 48
  • 62
0

Try this:

$.post('//url.to.python.com', { 
               "key": "value", 
               "key2": "value2"
             }, function(data){
              //Your returned data on success
 }).fail(function() {
   console.log( "error" );
 });
Alex Shilman
  • 1,547
  • 1
  • 11
  • 15