adding customized parameters to pass as json

岁酱吖の 提交于 2019-12-13 02:35:48

问题


I am sending the parameters using post method to my rails server using this code in titanium-

if (email.value != '' && password.value != '')
{
    loginReq.open("POST","http://192.168.0.187:3000/users/sign_in");
    var params = {
        email: email.value,
        password: password.value
    };
    loginReq.send(params);
}

On rails server side I am getting this output on console -

Parameters: {"password"=>"[FILTERED]", "email"=>"abcdefgh@gmail.com"}

But I need the output like this -

Parameters: {"user"=>{"email"=>"abcdefgh@gmail.com", "password"=>
FILTERED]"}, "commit"=>"Sign in"}

How to add user in parameters as above.


回答1:


I don't necessarily see the value in it, but you could change this:

var params = {
    email: email.value,
    password: password.value
};

to this:

var params = {
    user: {
        email: email.value,
        password: password.value
    },
    commit: "Sign In"
};

That would give you the output you're looking for.



来源:https://stackoverflow.com/questions/13974754/adding-customized-parameters-to-pass-as-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!