2010-05-28 116 views
0

我有一個窗體。我試圖通過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= 
+0

它格式化它在一個'名1 =值1&名2 = value2'格式...一樣在瀏覽器(GET請求)查詢字符串,這是你'.serialize想要什麼()',如果你發佈你的提交代碼,你會更容易看到你實際上在做什麼。 – 2010-05-28 11:43:00

+0

已更新..請建議 – ZX12R 2010-05-28 12:29:07

回答

0

怎樣的形式本身的樣子。我在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] 
+0

我的問題是我無法訪問發佈的任何值。 – ZX12R 2010-05-28 12:29:53

+0

嘗試...沒有運氣...你建議的方式通常適用於發佈請求...它在這種情況下返回零...我甚至嘗試params [:data] [:customer] [:uxName] .. – ZX12R 2010-05-28 12:54:00

+0

好的,你也可以發送完整的ajax請求,這樣就可以在任何地方查找錯誤。我們不能確定任何東西實際上是發送到網頁我猜:) – becquerel 2010-05-28 13:02:05