Jump to content

What am I doing wrong? Sending variables to PHP


ki

Recommended Posts

Mind you, I've altered and butchered my code several times trying to find why it's not sending anything even though it says it does.

 

geo.html

navigator.geolocation.getCurrentPosition(GetLocation);
function GetLocation(location) {
var usr_lat = location.coords.latitude;
var usr_long = location.coords.longitude;
$.ajax({
url: 'local_settings.php',
type: 'POST',
data: { user_lat : usr_lat, user_long : usr_long },
success: function(data)
                    {
                       alert("success! user_lat:" + data);
                    }
});
}

local_settings.php

if (isset($_POST['user_lat']) && isset($_POST['user_long'])) {
$_SESSION['user_lat'] = $_POST['user_lat'];
$_SESSION['user_long'] = $_POST['user_long'];
}

 

Link to comment
Share on other sites

How do you know it's not sending anything? Your local_settings.php script doesn't return anything back to the ajax, so data does not contain anything in your success() method. It just sets Session vars on the server.

I don't need anything returned, just sent to the server.

Cronix is right.  You should use firebug to determine if the ajax call is happening.  In your code snippet, I don't see you doing a session_start() at the top either.

There is a session_start(), I didn't include it in the code I posted. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.