title: Calling a function inside an AJAX success response?
body: <p>I'm basically trying to call a function which is outside of my AJAX inside the AJAX success response.</p>
  
  <p>To explain this better, this is what I have.</p>
  
  <p>These are two functions:</p>
  
  <pre><code>function watchCurrentPosition() {
      var positionTimer = navigator.geolocation.watchPosition(function(position) {
          setMarkerPosition(userLocation, position);
          map.panTo(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); 
  
      });
  
  }
  
  function clearmyWatch() { 
  
     navigator.geolocation.clearWatch(positionTimer);
  }
  </code></pre>
  
  <p>One of them keeps watching the users location and the other one 'should' stop it.</p>
  
  <p>And this is how I'm calling the <code>clearmyWatch();</code> function inside the AJAX:</p>
  
  <pre><code>$.ajax({
        type:"post",
        url:"TEST.PHP",
        datatype:"html",
        success:function(data)
        {
  clearmyWatch();
        }
      });
  </code></pre>
  
  <p>However, this doesn't work and the <code>watchCurrentPosition();</code> constantly running and I also get an error in my console.</p>
  
  <p>The error that I am getting is this:</p>
  
  <pre><code>ReferenceError: positionTimer is not defined
  </code></pre>
  
  <p>Could someone please advise on this issue?</p>
  
  <p>Thanks in advance.</p>