I am assembling data into an array for an ajax
call to a Rails controller action. Unfortunately, I don't know how to append the values of this array onto my query string so that they will end up in the params
object inside my controller action.
The array is a simple array of strings.
my_ids = ["1","2","3"]
My main query string is a serialized form.
I want to add this so that in my controller action:
params[:my_ids] == ["1","2","3"]
What can I do?
I am using Rails 3.2 and jQuery.
Try:
$.ajax({
url: '/controller/action',
type: 'POST',
dataType: "json",
data: {
my_ids: JSON.stringify(my_ids)
},
success: function () { alert('success'); },
error: function (event, request, settings) {
alert('Error' + ' : ' + settings); }
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.