添加自定义参数以作为 json 传递 [英] adding customized parameters to pass as json

查看:91
本文介绍了添加自定义参数以作为 json 传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用钛中的此代码使用 post 方法将参数发送到我的 rails 服务器-

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);
}

在 rails 服务器端,我在控制台上得到这个输出 -

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"}

如何在上面的参数中添加user.

How to add user in parameters as above.

推荐答案

我不一定能看到其中的价值,但你可以改变这个:

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

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

为此:

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

这会给你你正在寻找的输出.

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

这篇关于添加自定义参数以作为 json 传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆