The fastest easiest way to get it right.

serialize

NAME

x6.json.serialize

FUNCTION

The Javascript method x6.json.serialize takes a Javascript Object or Array and serializes it and adds the values to a JSON request previously initialized with x6.json.init.

This method accepts an object as its parameter.

When you call this function, the parameters sent back take the form of an associative array.

INPUTS

prefix - The base name of the parameter

object - the object to serialize.

EXAMPLE

Consider the following object that is serialized

      <script>
      var x = {
         parm1: [ 1, 2, 3],
         parm2: 'hello',
         parm3: {
             x: 5,
             y: 10,
         }
      x6.json.init('x4Page','myCustomPage');
      x6.json.addParm('x4Action','serialHandler');
      x6.json.serialize('example',x);
      <script>

Then on the server, you can grab the "example" parameter and you will get the following associative array:

      <?php
      # this is file x4myCustomPage.php
      class x4myCustomPage extends androX4 {

          # this handles the 'x4Action' specified above
          function serialHandler() {
              $example = gp('example');

              # ...the following code shows how
              #    the values that are in x4
              $example['parm1'][0] = 1;
              $example['parm1'][1] = 2;
              $example['parm1'][2] = 3;
              $example['parm2'] = 'hello';
              $example['parm3']['x'] = 5;
              $example['parm3']['y'] = 10;
          }
      }
      ?>

SOURCE

this.serialize = function(prefix,obj) {
    for(var x in obj) {
        if(typeof(obj[x])=='object') {
            this.serialize(prefix+'['+x+']',obj[x]);
        }
        else {
            this.addParm(prefix+'['+x+']',obj[x]);
        }
    }
}

User Comments

There are no user comments yet on this page.


Add A Comment

Comments will not appear until after they are moderated. Comments are usually moderated within a few hours on weekdays, but may take longer on weekends and holidays.

Name or nickname: (This will appear with your comment)


Email (this will never be displayed)


Enter your comment here. Use [b] and [/b] for bold, [i] and [/i] for italic, and [pre] and [/pre] for code samples. All literal HTML and PHP that you enter will be escaped out and displayed as you enter it.


Home |  Documentation |  Download |  Credits |  Contact |  Login
Andromeda © Copyright 2004-2010, Licensed under the GPL Version 2