views:

28

answers:

1

I have a form. I am trying to validate it through AJAX GET requests.

So i am trying to send the field values in the GET request data.

$('#uxMyForm').serialize();

the problem it is returning something undecipherable. I have used serialize before. This is totally bizzare.

the return value of serialize is

 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=

i have no idea how to use this.

Thanks

update:

My question is how do i process such a request? like this?

puts params[:data][:customer][:uxName]

my GET request trigger looks like this

$.get('/site/sign_up',{data : $('#uxMyForm').serialize() }, function(data){
 alert(data);
});

The above jquery lines generate the request.. on the action method i do the following

render :text => params

when i observe what is sent in the GET,in firebug 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=

the return value that i print in alert has

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=
A: 

How does the form itself look. I have no experience with Ruby on rails - and if it builds the form in a new exciting way - but it looks as if there's only two form elements: authenticity_token and customer - where customer is an array of items. This is the data you posted, but I urldecoded it and put in some linebreaks:

authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6/Q0zLeQqwIahJZJfE=
&customer[uxName]=
&customer[uxEmail]=
&customer[uxResidentialPhone]=
&customer[uxMobilePhone]=
&customer[uxDateOfBirth]=
&customer[uxAddress]=
&customer[uxResidentialStatus]=

What you could do is to serialize the form to an array and clean it up before sending it using jQuery ajax request. I did something similar once when I had to serialize .net runat-server form elements:

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

So instad of blabla$ABCPlaceHolder$tbxEmail I got tbxEmail in the array. You could do the same to get uxName, uxEmail etc instead of the customer array.

Note then again, however, due to my inexperience with ruby that this may not be the best solution - maybe there's a setting you can change to build the HTML form differently?

Updated:

I'm not sure how ruby works, but after a googling I found you should be able to receive your values using params:customer as an array.

params:customer should contain an array of the values

{:uxName => "", :uxEmail => "" }

I hope that tells you something on how to receive the data. Maybe (warning - wild guess!) like this?

params[:customer][:uxName]
becquerel
my problem is that i am not able to access any of the values posted.
ZX12R
tried...no luck... the way u suggested usually works for post requests... it returns a nil in this case... i even tried params[:data][:customer][:uxName]...
ZX12R
Ok, can you also send the full ajax request as well, just so it's possible to look for errors everywhere. We can't really be sure that anything is actually is sent to the page I guess :)
becquerel
have updated...
ZX12R
sorry my bad... solved it easily finally...$.get('url',$('form').serialize()) and not $.get('url',{ data : $('form').serialize()}) did the trick
ZX12R