[Dojo-interest] Anyone with a good example of io.bind using JSON?

Roger (Bordeaux) roger.bordeaux at ifrance.com
Tue Jan 2 09:31:53 MST 2007


Chris Andersoon a écrit , Le 02/01/2007 16:28:
> Looking for a good example of how to use io.bind and JSON to make requests from a PHP page.  Any help would be appreciated.
>
> Why are there no posts in this forum?  Much better than using mailing lists (searchable!).
> ---------------------------------------------------------------------
> Posted via Jive Forums
> http://forums.opensymphony.com/thread.jspa?threadID=56412&messageID=111787#111787
>
> _______________________________________________
> Dojo FAQ: http://dojo.jot.com/FAQ
> Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
> Dojo-interest at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>
>   
Hello Chris,

First of all, you need to write a php script that echo a well formatted 
JSON object string.

For example :

{ "data": [ { "id" : "1",  "name" : "my name 1" },
                { "id" : "2",  "name" : "my name 2" }
             ]
}

your js script must include the following

        dojo.io.bind({
                  url: 'myPath/myPhp.php',
                  method: "post",
                  sync : true,
                  load: function (type, data, evt) {
                      var myObject = eval('(' + data + ')');   // 
Convert the string to a JSON object
                      dojo.debug(myObject.data);              // will 
display two objects
                  },
                  sync : false,
                  error: function(type, error){
                      dojo.debug(error);
                  },
                  mimetype: "text/plain"
              });


I hope this can help.

Roger


More information about the Dojo-interest mailing list