I'm trying to pass in variables from a Javascript file to a PHP file. From my js file:
dataQuery = {
range: [[range.lower, range.upper]],
detail: { id: detail.id }
};
$.ajax({
type: "POST",
async: true,
url: scope.fetchUrl,
data: { query: dataQuery }
})
.done(function( data ) {
alert("success!");
}
In my php file I have session variables because I need to do oauth authentication.
if (isset($_SESSION['accessToken']))
{
$companyId = "1234";
$rollupFreq = "1H";
$oauth->setToken(
$_SESSION['accessToken'],
$_SESSION['accessTokenSecret']);
$apiUrl = ($apiBaseUrl
. '&company_id=' . urlencode($companyId)
. '&rollup_frequency=' . urlencode($rollupFreq)
. '&start_datetime_utc=' . urlencode($range['lower'])
. '&end_datetime_utc=' . urlencode($range['upper'])
);
try
{
header('Content-Type: application/json');
$data = $oauth->fetch($apiUrl);
$responseInfo = $oauth->getLastResponse();
print_r($responseInfo);
if (isset($_GET['query']))
{
$range = $_GET['query'];
print_r($range);
}
}
}
Nothing appears when I try to print $range, and when I try to use values from $range in the url I get "Undefined variable: range in url"
Any help would be appreciated!