Page 1 of 1
What wrong here?
Posted: Sun Mar 07, 2010 8:37 pm
by BrettCarr
json_decode is Returning Null This is the send to ajax
Code: Select all
<script language="javascript" type="text/javascript" src="/scripts/network.js"></script>
<script language="javascript" type="text/javascript">
function addDatadb()
{
myarray =<?= json_encode($_SESSION['batcharray'] ); ?>;
send( '/ajax/arrayclean.php', 'myarray=' + myarray, null, addDatadbRecv);
}
</script>
Seems ok Here
This is on the php side and in the responce tab of mozzilla debug window I get NULL
Code: Select all
<?PHP
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.php');
$db = new Database();
$db->connect();
json_decode($_REQUEST['myarray'], true);
var_dump(json_decode($_REQUEST['myarray'], true));
?>
kEEP GETTTING NULL can some please help me,, My boss is getting impatient and will behead me soon
Re: What wrong here?
Posted: Sun Mar 07, 2010 10:16 pm
by Weirdan
myarray =<?= json_encode($_SESSION['batcharray'] ); ?>;
myarray is an object here (check the page's source), and when you add it to 'myarray=' string later it results in something like 'myarray=Object' (put a breakpoint or alert into the 'send' function to see) which json_decode cannot parse (add var_dump($_REQUEST['myarray']) before decoding to see). You need to encode your object to json before sending if your /ajax/arrayclean.php script expects json
Re: What wrong here?
Posted: Sun Mar 07, 2010 10:44 pm
by BrettCarr
Weirdan wrote:
myarray =<?= json_encode($_SESSION['batcharray'] ); ?>;
myarray is an object here (check the page's source), and when you add it to 'myarray=' string later it results in something like 'myarray=Object' (put a breakpoint or alert into the 'send' function to see) which json_decode cannot parse (add var_dump($_REQUEST['myarray']) before decoding to see). You need to encode your object to json before sending if your /ajax/arrayclean.php script expects json
Thank you