Passing values from JavaScript to PHP using AJAX

前端 未结 4 1386
小鲜肉
小鲜肉 2020-12-22 07:12

I don\'t know why my code is not working, I am trying to send the coordinates from JavaScript to PHP using AJAX and I am able to pull values from JavaScript to textbox but v

4条回答
  •  隐瞒了意图╮
    2020-12-22 07:31

    The sole purpose of AJAX is to fetch and send data from a server without reloading the page.

    You don't need any data from the server. You need data from the BROWSER--namely--geolocation coordinates, so AJAX and php have no bearing on what you need to do here. This can be done in pure HTML.

    On the other hand, if you want to do something like save the coordinates to a database or use IP address as a fallback when the navigator doesn't support geolocation, that's when you could use the help of a server and AJAX would come into play.

    Simply replace your ajax function with getLocation().

    
      
        
          
          
       
       
          
         
       
    
    

提交回复
热议问题