views:

214

answers:

3

I have a .each() that is running a loop to find the following below..

Given the following which builds during the .each loop

id - desc
313 - blah blah
213 - blah blah
313 - blah blah
323 - blah blah

How can I form this data in JQUERY to be posted to the server (coldfusion)

A: 

You can model a record in a database in json, by using the column name for each column value.

example:

{ "column1" : "value1",
  "column2" : "value2",
    ...
  "columnN" : "valueN" }

If you are sending multiple DB records in one json transmission, then put them into an array:

[ { "column1" : "valueA.1", "column2" : "valueA.2", ... "columnN" : "valueA.N" },  
  { "column1" : "valueB.1", "column2" : "valueB.2", ... "columnN" : "valueB.N" },  
   ...
  { "column1" : "valueC.1", "column2" : "valueC.2", ... "columnN" : "valueC.N" } ]

If you are sending other information, put the array into an object:

{  "messageId" : "ASDUO38748",
   "timestamp" : 1873873873873, 
   "records":
    [ { "column1" : "valueA.1", ... "columnN" : "valueA.N" },  
      { "column1" : "valueB.1", ... "columnN" : "valueB.N" },  
       ...
      { "column1" : "valueC.1", ... "columnN" : "valueC.N" } ]
}
Cheeso
+1  A: 

I've learned this can be done with JSON in javascript, which is a component for Coldfusion:

http://www.json.org/js.html

AnApprentice
A: 

Look like a recordset in the browser. you can transform that as JSON , or you can try the javascript orm framework. like this:

var ds = new JDataset();

  var ds = new JDataset();
  ds.append();
  ds.setVal("Id", 1);
  ds.setVal("Desc", "a");
  ds.apend();
  ds.setVal("Id", 2);
  ds.setVal("Desc", "bb");
  ......
  ds.post({url: "server/service.php"});

you can see more detail at http://codeboogie.com

john