窗体序列化问题
问题描述:
我有一个窗体。我试图通过AJAX GET请求来验证它。窗体序列化问题
所以我想发送GET请求数据中的字段值。
$('#uxMyForm').serialize();
它返回的东西难以辨认的问题。我之前使用过序列化。这完全是b。。
连载的返回值是
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&customer%5BuxName%5D=&customer%5BuxEmail%5D=&customer%5BuxResidentialPhone%5D=&customer%5BuxMobilePhone%5D=&customer%5BuxDateOfBirth%5D=&customer%5BuxAddress%5D=&customer%5BuxResidentialStatus%5D=
我不知道怎么用这个。
感谢
更新:
我的问题是我如何处理这样的要求?喜欢这个?
puts params[:data][:customer][:uxName]
我的GET请求触发看起来像这样
$.get('/site/sign_up',{data : $('#uxMyForm').serialize() }, function(data){
alert(data);
});
以上的jQuery线产生的请求..在操作方法我这样做
render :text => params
当我观察是什么发送到GET,在萤火虫PARAMS
**data** authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
,我在警告打印则返回值
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
答
怎样的形式本身的样子。我在Ruby上没有经验 - 如果它以新的令人兴奋的方式构建表单 - 但它看起来好像只有两个表单元素:authenticity_token和customer - 其中customer是一组项目。这是您发布的数据,但我urldecoded,并把一些换行:
authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6/Q0zLeQqwIahJZJfE=
&customer[uxName]=
&customer[uxEmail]=
&customer[uxResidentialPhone]=
&customer[uxMobilePhone]=
&customer[uxDateOfBirth]=
&customer[uxAddress]=
&customer[uxResidentialStatus]=
你可以做的是形式序列化到一个数组中,并使用jQuery Ajax请求发送之前清理。我做了类似的事情,一旦当我不得不序列化.NET RUNAT服务器的表单元素:
var serializedData = $(form).serializeArray();
for(i=0; i < serializedData.length; i++)
{
// For each item in the array I get the input-field name after the last $ character
var name = serializedData[i].name;
var value = serializedData[i].value;
if(name.indexOf('$') != -1)
name = name.substr(name.lastIndexOf('$')+1);
serializedData[i].name = name;
}
var ajaxPostData = $.param(serializedData);
所以布拉布拉$ ABCPlaceHolder $ tbxEmail我的阵列中得到tbxEmail的instad。你可以做同样的事情来获得uxName,uxEmail等,而不是客户数组。
然后请注意,然而,由于我对ruby没有经验,这可能不是最好的解决方案 - 也许有一个设置可以更改为以不同的方式构建HTML表单?
更新时间:
我不知道是如何工作的红宝石,但谷歌上搜索,我发现后,你应该能够接收使用PARAMS你的价值观:客户为数组。
PARAMS:客户应包含的值
{:uxName => "", :uxEmail => "" }
我希望告诉您如何接收数据的东西的数组。也许(警告 - 狂猜!)这样?
params[:customer][:uxName]
它格式化它在一个'名1 =值1&名2 = value2'格式...一样在浏览器(GET请求)查询字符串,这是你'.serialize想要什么()',如果你发布你的提交代码,你会更容易看到你实际上在做什么。 – 2010-05-28 11:43:00
已更新..请建议 – ZX12R 2010-05-28 12:29:07