I'm Italian almost a newbie in javascripting and server side rule configuration. I'm creating a webside page, and intend to use a part of code of gpxtruder.xyz.
I have permission of owner (Jim Denova jim@anoved.net) to use original code, as it's released under opensource license.
In index.html page code is following:
<form enctype="multipart/form-data" method="get" name="gpxform">
<p><input type="radio" name="gpxsource" value="0" id="gpxsource_upload" onchange="return toggle(event, 0, 'gpxfile') && toggle(event, 1, 'gpxsample');" />
<label for="gpxsource_upload">Upload GPX:</label>
<input type="file" id="gpxfile" /><br />
<input type="radio" name="gpxsource" value="1" id="gpxsource_sample" onchange="return toggle(event, 0, 'gpxfile') && toggle(event, 1, 'gpxsample');" checked />
<label for="gpxsource_sample">Sample GPX:</label>
<select id="gpxsample">
<option value="0" selected>South Mountain</option>
<option value="1">Vestal XX (20k road race)</option>
</select>
<h1>Hello, my name is <span id="name"></span></h1>
<script>
let gpxsource = "1"
let name = gpxsource;
document.getElementById("name").innerHTML = name;
</script>
you could choose a pre selected track to show result or load your own gpx file
parameters are sent to gpxtruder.js file, follows part of code processing data first part of code
if (radioValue(form.gpxsource) === 0) {
// Assign a local URL to the file selected for upload
// https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL
var files = document.getElementById('gpxfile').value;
window.alert(gpxfile);
//var files = document.getElementById('gpxfile').files;
window.alert(files);
if (files.length === 0) {
Messages.error('No GPX file selected.');
return;
}
// upload_url = window.URL.createObjectURL(files[0]);
upload_url = files
} else {
if (parseInt(form.gpxsample.value) === 0) {
upload_url = "https://gpxtruder.xyz/gpx/SouthMtn.gpx";
} else if (parseInt(form.gpxsample.value) === 1) {
upload_url = "https://gpxtruder.xyz/gpx/VXX.gpx";
} else {
return;
}
}
window.alert(upload_url);
window.alert(options);
loader(options, upload_url);
if (radioValue(form.gpxsource) === 0) {
window.URL.revokeObjectURL(upload_url);
}
second part of code
var loader = function(options, gpx_url) {
window.alert(gpx_url);
Messages.clear();
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4 /*&& req.status == 200*/) {
if (!req.responseXML) {
Messages.error("This doesn't appear to be a GPX file.");
return;
}
window.alert(req.responseXML);
// Attempt to parse response XML as a GPX file.
var pts = Parser.file(req.responseXML, options.zoverride, options.zconstant);
if (pts === null) {
return;
}
// If all is well, proceed to extrude the GPX path.
g = new Gpex(options, pts);
}
};
// submit asynchronous request for the GPX file
req.open('GET', gpx_url, true);
req.overrideMimeType("text/xml");
req.send();
};
my problem is stricktly connected to upload_url = "https://gpxtruder.xyz/gpx/VXX.gpx";
if I change url address and insert my server web space, where I hosted gpx files,even if I use original file, page answer "This doesn't appear to be a GPX file."
I didn't find were problem could be.
Could be a javascript related problem? (but code and file are exacly a dupe of original) or could be a server side configuration problem were gpx file is hosted?
original file could be found
https://gpxtruder.xyz/index.html
https://gpxtruder.xyz/js/gpxtruder.js
thanks for help, if any possible.
Problem was a server side configuration, exactly a: CORS header 'Access-Control-Allow-Origin' missing
I'm a newbie and didn't know how browser console works and how could be useful
solved via .htaccess
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
answer found on CORS header 'Access-Control-Allow-Origin' missing