I want to save some GET
to my database using $.ajax()
but the data only returns empty. Here's my code:
$.ajax({
url: 'file.php?data=',
type: 'GET',
data: {
f: $('input[name="textfield"]').val(),
c: $('#coordinates').html(),
a: $('#address').html()
},
success: function(s) {
console.log(s);
}
});
The PHP part look like this:
if(isset($_GET['data'])) {
echo $_GET['f'].' - '.$_GET['c'].' - '.$_GET['a'];
}
This code only returns --
. What have I missed?
Update
The link from the network tab in developer tools in Chrome, shows as follows: http://.../send/data?f=hello&c=62.3875%2C+16.325556&a=KLOCKEN+520%2C+840+13+Torpshammar%2C+Sverige
(send/data
is file.php?data=
). But when I replace echo $_GET['f']...
with var_dump($_GET)
it prints the following:
array(1) {
["data"]=>
string(0) ""
}
Why can't I get the data from $_GET['f']
, $_GET['c']
, and $_GET['a']
with the code above?