I need to be able to decode multiple parameters from the data portion of an ajax call to a perl cgi script. I know that everything else is working with my code, but for whatever reason I can't seem to get the decode method of the JSON module to work properly to restore the data from JSON format to parameters again. The data in my jQuery ajax call is set up like this, which is correct.
data: {
maxRows: 5,
productName: request.term
}
However, something is wrong with the way that I'm trying to parse it into perl.
my $json = JSON->new->utf8->allow_nonref;
my $json_text = $cgi->param('data');
my $json_array = $json->decode( $json_text );
I know that the correct end result should be an array of hashes. If I can get that far I know I'll be fine. However, my decode line does not work and actually causes the whole script to fail when it's executed.
I have looked around extensively and I just can't figure this out. I'm pretty sure it's some very small tweak.
Am I getting the parameter correctly by using $cgi->param('data') ? Does it end up being named data, or is it something else?