Long polling with json and PHP

I try to make a system that keeps track of certain statistics for a user like, the number of new messages etc.

This is what I have sofar:


<li><a href="#" class="">Berichten <span class="badge credits"><?= $credits ?></span></a></li>
<li><a href="#" class="">Berichten <span class="badge nw_berichten"><?= $nw_berichten ?></span></a></li>


  function profielAantallen(){
            type: "POST",
            url: "/profielen/aantallen",
            dataType: 'json',
            async: true,
            cache: false,
            success: function(data){
                if ( data ) {
                setTimeout(profielAantallen, 10000);

url: “/profielen/aantallen”

    public function aantallenAction()
        $profiel    =    $this->session->get('profiel');
        $aantallen  =   $this->aantallen->get_profiel_aantallen($profiel);
        echo json_encode(array(
            'credits'        => $credits,
            'nw_berichten' => $nw_berichten

I thought this would do the trick but I get an error that both values are undefined. Does anyone see what i am doing wrong? Thank you in advance

Where are you defining $credits and $nw_berichten ?

Hi Mittineague thanks for the reply, apparently I got an Illegal string offset on $credits. As a test I had 30 credits added to one profiel which gave me the warning. I jut changed it to 5 credits and it i working fine. What can be the reason it gave me an Illegal string offset on credits while the number of credits was 30 and I don;t get that warning when the number is 5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.