File size: 1,142 Bytes
14effdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const jsonBtn = document.getElementById("getJson");
const apiBtn = document.getElementById("getApi");
const output = document.getElementById("output");
const coordsForm = document.getElementById("coords-form");

function formData2json(dataId, newObj={}) {
    const formData = new FormData(dataId);
    formData.forEach(function(value, key){
        newObj[key] = value;
    });
    return JSON.stringify(newObj);
}

coordsForm.addEventListener('submit', event => {
    event.preventDefault();
    const inputJson = formData2json(coordsForm)
    console.log("inputJson", inputJson, "#");

    fetch('/infer_samgeo', {
        method: 'POST', // or 'PUT'
        body: inputJson,  // a FormData will automatically set the 'Content-Type',
        headers: {"Content-Type": "application/json"},
    }).then(function (response) {
        return response.json();
    }).then(function (data) {
        console.log("data:", data, "#")
        output.innerHTML = JSON.stringify(data)
    }).catch(function (err) {
        console.log("err:", err, "#")
        output.innerHTML = `err:${JSON.stringify(err)}.`;
    });
    event.preventDefault();
});