This is an old question, so I'm not sure if this is interesting for you, but maybe someone else is interested in this question.
, javascript Perl ajax - JSON - "JSON.stringify(jsArray)"; - Perl script. , .
index.html
<!DOCTYPE html>
<html>
<head>
<title>Testing ajax</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#test").click(function(){
var jsArray = ["employee", "admin", "users", "accounts"];
var jsArrayJson = JSON.stringify(jsArray);
$.ajax({
type: 'POST',
url: '/cgi-bin/ajax/stackCGI/processJsArray.pl',
data: { 'searchType': jsArrayJson},
success: function(res) {alert(res);},
error: function() {alert("did not work");}
});
})
})
</script>
</head>
<body>
<button id="test" >Push</button>
</body>
</html>
processJsArray.pl
use strict;
use warnings;
use CGI;
use JSON;
my $q = CGI->new;
my @myJsArray = @{decode_json($q->param('searchType'))};
print $q->header('text/plain;charset=UTF-8');
print "first item:"."\n";
print $myJsArray[0]."\n";