I've been following tutorials trying to get this to work properly--but the data will not display anywhere on my website. For a while it was showing the json_encode return value, but Now its note even displaying that.
function currentStarMapURL(URL)
{
$('#starmap').load(URL, {},
function()
{
$('#loader').hide();
fullStarInformation(URL);
starInformation();
$.ajax(
{
url:'world1.php', error: function () { }, dataType:'json',
complete: function(data)
{
denial = false;
$('#credits').load(data.credits);
$('#fuelleft').load(data.fuel);
$('#energyleft').load(data.energy);
}
});
return false;
}
);
}
PHP
<?php
require_once("lib/bootstrap.php");
$money = new userStats($db, $_SESSION['uid']);
#$upgrades = new upgrades($db, $_SESSION['uid']);
$credits = $money->balance;
$energy = $money->energy;
$fuel = $money->fuel;
$upgrade = $upgrades->parseXML();
$array = array(
'fuel' => $fuel,
'energy' => $energy,
'credits' => $credits,
'upgrades' => $upgrade
);
header('Content-type: application/json');
return json_encode($array);
?>
this will help you figure out that is the problem
in your js code try this
var jqxhr = $.ajax( "example.php" )
.done(function(data) {
console.log( "success" );
console.log( data );
}).fail(function(data) {
console.log( "fail" );
console.log( data );
}).always(function() {
console.log( "complete" );
console.log( data );
});
always use your console to check the data if something go wrong
in your php try the follwing
echo json_encode($array);
die();
jQuery's .load()
accepts a URL from which to load content as an argument. So, I'm guessing what you need is this:
$('#credits').html(data.credits);
$('#fuelleft').html(data.fuel);
$('#energyleft').html(data.energy);
where you use .html()
instead of .load()
.