Welcome Guest, Not a member yet? Register   Sign In
Send out AJAX to bring back his body [solved - sort of]
#1

[eluser]obiron2[/eluser]
Hi guys,

this one has me stumped.

I have found a nice Javascript routine that will take PHP serialize() and unserialze it as a javascript object. This means I can access the PHP objects properties and values to insert into DOMobj.in nerHTML

The Unserialize() function looks at the first character of the Ajax response to see what type of serialisation it is (object, string, integer etc).

I was testing it with the following function in my controller

Code:
function nextLevel($thislevel=0)
    {
       $this->load->model('clock_model');
       $return->newlevel=$thislevel +1;
       $return->hours=0;
       $return->mins=3;
       $return->secs=40;
       while ($return->secs > 59)
       {
         $return->secs=$return->secs - 59;
       }
       $result=serialize($return);
       //$result = trim($result);
       //str

       //  The serialised string looks like this
       //  O:8:"stdClass":4:{s:8:"newlevel";i:2;s:5:"hours";i:0;s:4:"mins";i:3;s:4:"secs";i:40;}
       print $result;
    }

This is the code for the clock_model (note it is not currently being called)

Code:
class Clock_model extends Model {

    function Clock_model()
    {
        parent::Model();
        $this->load->database();
    }

    function getLevelData($LevelID=0)
    {
      $SQL = "SELECT * from CL_Blinds where Level = $LevelID Limit 1";
      $Result = $this->db->query($SQL);
      if ($Result->num_rows()==0)
      {
        return null;
      }
      $Return = $Result->row();
      return $Return;
    }

}

When I leave the
Code:
$this->load->model('clock_model');
in the controller function, the response seems to include four spaces before the text string. When I comment it out, it works fine.

Any idea why and how I stop it. As far as I can see the Model and controller are clean and not outputting any white space.

Cheers

Obiron
#2

[eluser]Michael Wales[/eluser]
Not sure why it's happening - but a potential solution: trim()
#3

[eluser]obiron2[/eluser]
nope. tried that
#4

[eluser]obiron2[/eluser]
Deleted the model and created it again.

It seems to be OK now (even though I cut and pasted from the original). It must have been an issue with the actual php file!!

Thanks anyway

Obiron




Theme © iAndrew 2016 - Forum software by © MyBB