-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Javascript arrays don't decode well #84
Comments
You don't seem to be applying the However, the desired result you want won't work with the input you provide, whether in Ring: user=> (nested-params-request {:params {"contraints[0][]" ["A" "B"], "want" "C"}})
{:params {"want" "C", "contraints" {"0" ["A" "B"]}}} Or in Rails: irb> Rack::Utils.parse_nested_query("constraints[0][]=A&constraints[0][]=B&want=C")
=> {"constraints"=>{"0"=>["A", "B"]}, "want"=>"C"} |
@weavejester Is the conversion of {constraints: [["A", "B"]]} into {"constraints[0][]" ["A" "B"]} done on the jQuery side, or the Ring side? Because nested arrays serialize just fine into JSON in general:
@mrocklin You don't state in the ticket if this gives the same result with a POST as it does with GET. Does it? Because GETs have to stuff their parameters into the HTTP URL arguments, I can understand why this would go sideways -- but maybe POSTs are more robust (since you can just pass data, unmunged...?). I guess I'm confused exactly where this simple thing is breaking down. And, what people usually do about it. Thanks! |
Post does better because it does actually decode the query-string and push the result into the $.post("/query/", {want: "C", constraints: [["A", "B"]]},
function(data, aStatus, dummy){
alert(data);
}); {:scheme :http,
:query-params {},
:form-params {"constraints[0][]" ["A" "B"], "want" "C"},
:request-method :post,
:query-string nil,
:params {:want "C", :constraints {"0" ["A" "B"]}},
:body #<HttpInput org.eclipse.jetty.server.HttpInput@16535bf>} From what @weavejester writes it seems that my issue is really what I should expect from any system. It seems like the best path may be to kludge together a local array-from-map function. |
On the jQuery side, since that's where the request is coming from.
Or just use JSON, instead of trying to encode a data structure in form parameters, which aren't really designed for that. |
Nested JavaScript arrays in AJAX call data to a ring application fail to parse. I think I can reproduce the error as far down as
form-decode
.Disclaimer: I'm new to Ring and web programming in general. Please correct me if this ticket should be filed elsewhere.
AJAX call
Result on Server
Desired Result
The text was updated successfully, but these errors were encountered: