On Feb 27, 4:27 pm, Javier Quarite <jquari...@gmail.com> wrote:
> On Mon, Feb 27, 2012 at 3:43 PM, Vell <lovell.mcilw...@gmail.com> wrote:
> > Hello all,
>
> > I'm trying to write a jquery function where I am posting some data from a
> > form. I am wondering is there a way to select the particular param that I
> > want to use when I submit the data to $.ajax(). I don't believe it makes
> > sense to create a hidden field just to use with $.ajax() but I can't seem
> > to figure out how to get to the params key/value using jquery.
>
> > The code that I am attempting to use is:
> > $.ajax({
> > url: "/app/controller/action",
> > type: "POST",
> > data: {code : 'param[:value]' or ??}
> > });
>
> > Can this be done at all? if so, what would be a good approach?
>
> > Thanks,
>
> > -
>
> Lets say you have a form with an ID new_form
>
> var form = $('#new_form');
> $.ajax({
> url: form.attr("action"),
> type: "POST",
> data: form.serialize(),
> cache: false,
> beforeSend: function(){
> //something here
> },
> complete: function(){
> // something here
> },
> success: function (result) {
>
> //here comes whatever you want
>
> }
>
> });
>
> so instead of form.serialize() you have to send the variable you want
> I think in the success function, or before send you should do an alert of
> what is sending, then you will choose what you want to show after the
> success
Thanks for the quick response. That does give me a little more clarity
but I guess my question was how do I define my variable with a value
that is in params? When I do alert($("#params")) I get a response of
object Object. When I do alert($(form.serialize())), I seem to get
most of the params values except for the one that I want. It also
doesn't look like its in an array so I can't chose the element that I
want. Granted I am new to jquery and don't fully understand
serialization and a great many other things. I believe the first alert
is telling me that I can get to the entire params object using an id
of params. But how do I get to the value within it to be able to
specify my data variable in my $.ajax() statement? Sorry If I am not
making much sense...
>
> That's all, hope it helps
>
> Javier Q
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment