Browse Source

test javascript

testing
Burathar 4 years ago
parent
commit
db9dfd0964
  1. 38
      app/templates/player_base.html

38
app/templates/player_base.html

@ -8,16 +8,20 @@ @@ -8,16 +8,20 @@
{% block scripts %}
{{ super() }}
<script>
var csrftoken = $('meta[name=csrf-token]').attr('content')
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
$(document).ready(sendLocation)
function sendLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(postCoordinates, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
})
}
setInterval(function() {sendLocation()}, 10 * 1000);
function sendLocation(position) {
function postCoordinates(position) {
$.ajax({
type: "POST",
url: "{{ url_for('main.send_location', username=current_user.name) }}",
@ -32,6 +36,15 @@ function sendLocation(position) { @@ -32,6 +36,15 @@ function sendLocation(position) {
});
}
var csrftoken = $('meta[name=csrf-token]').attr('content')
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
}
})
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
@ -50,14 +63,5 @@ function showError(error) { @@ -50,14 +63,5 @@ function showError(error) {
}
}
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(sendLocation, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
})
</script>
{% endblock %}
Loading…
Cancel
Save