I'm trying to do a simple post request to use the OGRE web app to convert JSON files to shapefiles.
I wrote this code, but the file doesn't download like it supposed to be, [edit] and it doesn't even upload the json.
The website specifies this as the input request params:
http://ogre.adc4gis.com/convertJson with one of the following params:
json - text of the GeoJSON file
jsonUrl - the URL for a remote GeoJSON file
outputName (optional) - the name for the resulting zip file
skipFailures (optional) - skip failures
What am I doing wrong ?
<html>
<head>
<script src="http://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
</head>
<body>
<input type="button" value="Send Post" onclick="sendPost()">
<script>
var data = { "type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": { "type": "Point", "coordinates": [102.0, 0.5] },
"properties": { "prop0": "value0" }
}]
};
function sendPost() {
$.ajax({
type: "POST",
url: 'http://ogre.adc4gis.com/convertJson',
json: data,
success: success
});
}
function success(result) {
alert('Process achieved!');
}
</script>
</body>
</html>
I get this error:
Object {error: true, msg: "No json provided"}
What is the problem ?
but the file doesn't download like it supposed to be.
The file isn't supposed to download.
You have made an Ajax request. The response to it will be handled by JavaScript. It will only be handled by JavaScript. The JavaScript you wrote to handle it just calls alert
(and nothing else).
If you want the browser to handle it in the same way as if you had submitted a regular form (without JavaScript) then you should submit a regular form. The whole point of Ajax is to handle the response in a custom way.
there is no such property json
for jquery ajax, to add the json as post-data do like this:
function sendPost() {
$.ajax({
type: "POST",
url: 'http://ogre.adc4gis.com/',
data: {json:JSON.stringify(data) },
success: success
});
}
in your success handler you will have the response in result
dont expect your browser to download something as stated in Quentins Answer.