What wrong here?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BrettCarr
Forum Newbie
Posts: 22
Joined: Fri Feb 12, 2010 6:45 pm

What wrong here?

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: What wrong here?

Post 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
BrettCarr
Forum Newbie
Posts: 22
Joined: Fri Feb 12, 2010 6:45 pm

Re: What wrong here?

Post 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
Post Reply