I am trying to get Ajax to load a form which is created in PHP and assigned a variable $copen.
In Ajax how do I go about placing the variable in the URL part of Ajax to open and retrieve the JSON data.
The code in my Ajax script:
$.ajax({
async: false,
url: 'queryme3x.php',
type: 'get',
dataType: "json",
success: function(data) {
$.each(data, function(i, val){
val.timestamp = Date.parse(val.date);
// save the years so we can create year markers
var year = new Date(val.timestamp).getFullYear();
if (years.indexOf(year) < 0)
years[years.length] = year;
// combine data & templqate
var html = postTemplate(val);
$('#timeline').append(html);
And the code in my PHP script:
<?php
require("dbenter.php");
$checks = $_POST['check1'];
if (isset($checks) && !empty($checks)){
foreach ($_POST['check1'] as $tst1) {
$tst1 = implode("' OR Category ='", $checks);
}
$checks1 = "'".$tst1."'";
}
$sql = "SELECT * FROM tstline WHERE Category =$checks1";
$result = mysql_query($sql);
$rows = array();
while ($r = mysql_fetch_assoc($result)) {
$row = array();
$row['date'] = $r['date'];
$row['Year'] = $r['Year'];
$row['Category'] = $r['Category'];
$row['Subcategory'] = $r['Subcategory'];
$row['Location'] = $r['Location'];
$row['Shortdescription'] = $r['Shortdescription'];
$row['Fulldescription'] = $r['Fulldescription'];
array_push($rows,$row);
}
$fdate = date('mdy');
$fp = $checks1.$fdate.".json";
$stripout = array("'","OR","="," ","Category");
$nfname = str_replace($stripout,"",$fp);
echo $nfname;
$tst2 = $checks;
if (file_exists($nfname)) {
$copen = $nfname;
return true;
}
else {
$copen = fopen($nfname,'w+');
fwrite($copen, json_encode($rows));
}
echo json_encode($rows);
?>
As you can see its the value of $copen that I want to carry into the Ajax URL section.
Any help would be appreciated :)