I'm working on a Catalyst database project and trying to do some AJAX requests via jQuery. Parameters are being sent OK, as can be seen in image 1.
Notice that both "diagnosis" and "type_consents" (and their corresponding dates) are sent as an array of values (value 1, value 2, ... value n).
Now for the server side treatment, Catalyst::Request
allows for easy data retrieval through $req->parameters
, but it doesn't seem to be working for me.
I'm doing it like this:
my $params = $c->request->parameters; #Retrieving all parameters
my @type_consents = $params->{type_consent};
my @date_consents = $params->{date_consent};
my @diagnosis = $params->{diagnosis};
my @date_diagnosis = $params->{date_diagnosis};
Then I need to loop these arrays and make an insertion for each pair of values (diagnosis|date , consent|date)
. Plus, I need to store and process all transactions and execute them all at once in an eval()
block, so I'm doing it like this:
my %transactions;
# Diagnosis
my $diag_index = 0;
foreach my $key ( 0 .. $#diagnosis ) {
$transactions{diagnosis}{$diag_index} = $diagnosis_mod->new(
{
subject_id => $subject_id,
diagnosis_date => $date_diagnosis[$key],
diagnosis => $diagnosis[$key],
diagnosis_comment => "",
suggested_treatment => ""
}
);
print STDERR "\n" . $date_diagnosis[$diag_index];
print STDERR "\n DEBUG: $date_diagnosis[$diag_index] | $diagnosis[$diag_index] | key: $diag_index";
print STDERR "\n DEBUG2:" . Dumper( @date_diagnosis ) . " | " . Dumper( @diagnosis );
$diag_index++;
}
# I'm avoiding evaluating and performing the transactions so neither eval() nor database impact are shown above.
Those debugs print the following:
Does this suggest that my "array" is just a unidimensional variable with a string? I tried splitting it but that doesn't work either.