I have been working on this for 1 hour with no such luck. Any help would be appreciated.
I have a cgi script with which creates these select param values:
print "Please select a dkversion to compare : <br><br>";
print "<select name='dkversion' id='dkversion' size='6' multiple='multiple'>";
foreach my $values ('ASDF123GS v0.01 models eval QA <-> apple', 'ZXCV534GS v1.01 models eval QA <-> pineapple')
{
print "<option value=\"" . $values . "\" >" . $values . "</option>";
}
print "</select>";
print "</form>";
I have another html page that uses jquery/javascript to process the inputs:
var scalarstr = "";
$("#dkversion :selected").each(function () {
scalarstr += "dkselected=" + encodeURIComponent($(this).val()) + "&";
});
$.get("./scripts/modelQA_correlation.cgi?" + scalarstr + "&menu_mode=2",function(data){
});
Coming Back to cgi page to process the multiple selects, I do a dump of the inputs and noticed it isn't separating the values:
$VAR1 = { 'dkselected' => 'AS开发者_如何学GoDF123GS v0.01 models eval QA <-> apple�ZXCV534GS v1.01 models eval QA <-> pineapple', 'menu_mode' => '2' };
Why isn't the dkselected values being separate into it's two parts??
A safer approach here is to let jQuery encode the string, let's get the values from the <select>
, store them in an array, via .serializeArray()
, then add the menu_mode
to it, like this:
var params = $("#dkversion").serializeArray();
params.push({ name: 'menu_mode', value: '2' });
$.get("./scripts/modelQA_correlation.cgi", params, function(data){ });
You can test it out here. This does everything your code above does, but I hope you'll agree much simpler and easier to maintain. This works by passing an object as the $.get()
data
option, which internally calls $.param()
to get the final string, so you can test/see the result yourself like I have in the demo.
If you are doing something like $args = CGI::Vars
, then you're running afoul of the quirk in how CGI.pm handles multiple values. You'll need to split the string on "\0"
(null).
Another approach is to use the param method: @vals = $q->param('dkversion');
精彩评论