How can I build params via javascript?

I want use javascript to send a javascript object back to the rails.How
can I do it.

If I write like below:
var material={code:“000”,name:“test”};
params={“material”:material}

then I the params look like this:
{"_dc"=>“1217663839339”}

I can get nothing at the serverside.

Now I write the code like below:
var material={code:“000”,name:“test”};
params={“material”:Object.toJSON(material)}

and at server side,I must use “JSON.parse”
require ‘json’
def create
material=Material.new(JSON.parse(params[:material]))
end

then I can create the material object.If I write like below:
material=Material.new(params[:material])
I got nothing!

My question is : How can I create the params use javascript then I can
get it direct at the serverside rather than use the “JSON.parse”

On 2 Aug 2008, at 09:03, Michael G. wrote:

{"_dc"=>“1217663839339”}

I can get nothing at the serverside.

Now I write the code like below:
var material={code:“000”,name:“test”};
params={“material”:Object.toJSON(material)}

What are you then doing with the params (on the client side), ie how
are you submitting your request?

Fred

Frederick C. wrote:

On 2 Aug 2008, at 09:03, Michael G. wrote:

{"_dc"=>“1217663839339”}

I can get nothing at the serverside.

Now I write the code like below:
var material={code:“000”,name:“test”};
params={“material”:Object.toJSON(material)}

What are you then doing with the params (on the client side), ie how
are you submitting your request?

Fred

Hi,Fred.Thanks for your reply.
I used the extjs on the client side,it’s a javascript framework.
Here is a sample form:

var form=new Ext.FormPanel({
labelWidth: 100,
title:“material”,
frame:true,
border:false,
width: 820,
items:[
{fieldLabel: ‘code’,id:“curcode”,name:“material[code]”},
{fieldLabel: ‘name’,id:“curname”,name:‘material[name]’}
],
buttons: [
{text:‘save’,handler:function(){
form.getForm().submit({
method:‘POST’,
waitTitle:‘Connecting’,
waitMsg:‘Sending data…’,
url:’/material/create’,
success:function(){Ext.Msg.alert(“sucess”,“sucess”);},
failure:function(form, action){
if(action.failureType == ‘server’){
obj =
Ext.util.JSON.decodeaction.response.responseText);
Ext.Msg.alert(‘failure’, obj.errors);
}else{
Ext.Msg.alert(‘Warning!’, 'Authentication server is unreachable
: ’ + action.response.responseText + “abcd”);}
itemform.getForm().reset();
} });
}}
]
})

if I submit it,the params is what I want:
{“material”=>{“code”=>“000”,“name”=>“test”}}

Now I write a new application.

var queryform=new Ext.FormPanel({
labelWidth: 100,
title:“material”,
frame:true,
border:false,
width: 820,
items:[
{fieldLabel: ‘code’,id:“curcode”,name:“material[code]”},
{fieldLabel: ‘name’,id:“curname”,name:‘material[name]’}
]
})

var form=new Ext.FormPanel({
labelWidth: 100,
title:“material”,
frame:true,
border:false,
width: 820,
items:[{layout:‘form’,xtype:‘panel’,autoHeight:true}],
buttons: [
{text:‘save’,handler:function(){
var material={
code:Ext.getCmp(“code”)?Ext.getCmp(“code”).getValue():"",
name:Ext.getCmp(“name”)?Ext.getCmp(“name”).getValue():""
};
var mbsstore = new Ext.data.Store(
{
proxy: new Ext.data.HttpProxy({url: ‘/material/queryresualt/’}),
baseParams:{“material”:Object.toJSON(material)},
reader: new Ext.data.JsonReader({root:‘items’},[ ‘id’,
‘name_native’]),
remoteSort: true
});
mbsstore.load();
}}]})

now the params is: {“material”=>"{“code”:“000”,“name”:“test”}"}
if I rewrite the code like this: baseParams:{“material”:material)},the
params is: {"_dc"=>“1217663839339”}

My question is,I want send a javascript object(like the material) back
to the serverside,how can I build the params like
{“material”=>{“code”=>“000”,“name”=>“test”}}

On 2 Aug 2008, at 11:28, Michael G. wrote:

params={“material”:Object.toJSON(material)}

snip

My question is,I want send a javascript object(like the material) back
to the serverside,how can I build the params like
{“material”=>{“code”=>“000”,“name”=>“test”}}

I know nothing about extjs. You need to convince it to submit data
that looks like

material[code]=000&material[name]=test

Fred

On 2 Aug 2008, at 12:07, Michael G. wrote:

to the serverside,how can I build the params like
spectial format.But,there is some question:
I know nothing about extjs, so i’d be hard pushed to give you a sample

what is [material[code]=000&material[name]=test],a string ?
And where is the key?

I mean that the body of the post should be
material[code]=000&material[name]=test

or if it’s a get request, then the url should look like

some_controller/some_action?material[code]=000&material[name]=test

Fred

Frederick C. wrote:

On 2 Aug 2008, at 12:07, Michael G. wrote:

to the serverside,how can I build the params like
spectial format.But,there is some question:
I know nothing about extjs, so i’d be hard pushed to give you a sample

what is [material[code]=000&material[name]=test],a string ?
And where is the key?

I mean that the body of the post should be
material[code]=000&material[name]=test

or if it’s a get request, then the url should look like

some_controller/some_action?material[code]=000&material[name]=test

Fred

Thank you,Fred.I got it.I have created the params successfully.
I created the params like below
params:{“material[code]”:“000”,“material[name]”:“test”}

Thand you very much!

Frederick C. wrote:

On 2 Aug 2008, at 11:28, Michael G. wrote:

params={“material”:Object.toJSON(material)}

snip

My question is,I want send a javascript object(like the material) back
to the serverside,how can I build the params like
{“material”=>{“code”=>“000”,“name”=>“test”}}

I know nothing about extjs. You need to convince it to submit data
that looks like

material[code]=000&material[name]=test

Fred

Hi,Fred.Can you give me a sample?I can translate the javascript to the
spectial format.But,there is some question:

what is [material[code]=000&material[name]=test],a string ?
And where is the key?