I am quite new to Ajax and I am looking to use it to send JavaScript parameters to an MVC controller.
The problem I am having is it is sending it multiple times rather than just once. Most it just sends it twice.
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
}
}
function showPosition(position) {
myFunc = function(){};
$.ajax({
url: '@Url.Action("Create")',
data: { latitude: position.coords.latitude, longtitude: position.coords.longitude},
dataType: 'json',
});
window.setInterval(getTime, 1000);
}
I have tried using window.setInterval(getTime, 1000);
to maybe escape a loop I might be caught in but I'm unsure.
Thanks.