I am trying to pull a JSON I created using this PHP code:
if ($result=mysqli_query($conn,$sql))
{
$rowcount=mysqli_num_rows($result);
}
$myJSON = json_encode($rowcount);
echo $myJSON;
I am trying to add the value $myJSON to a Javascript variable. Currently, my code looks like this:
var maxqty;
$.getJSON('[URL in here or .php file]', data, function(jsonData) {
maxqty = jsonData;
});
I know this should be a really simple thing to do, but I can't understand where my code is going wrong. I think either my PHP file isn't outputting the correct format or my $.getJSON
call is wrong. I get an error when I make my $.getJSON call saying
Uncaught reference error: data is not defined.
Any advice?