title: How to send data to Perl script via ajax?
body: <p>I want to send data to Perl script via ajax, and to receive a json format back from it. But it doesn't work. I know something is wrong in the following scripts. Does anyone know how to fix it?</p>
  
  <p>jQuery code:</p>
  
  <pre><code>$("#test").click(function(){
      var ID = 100;
      var data = {
          data_id : ID                                                                        
      };
  
      $.ajax({        
          type: "POST",
          url: "ajax.cgi",
          data: data,
          success: function(msg){
              window.alert(msg);
          }       
      });
  });
  </code></pre>
  
  <p>ajax.cgi (perl script):</p>
  
  <pre><code>#!/usr/bin/perl
  
  use CGI;
  use DBI;
  
  $cgi = CGI-&gt;new;
  
  # Here I'd like to receive data from jQuery via ajax.
  $id = $cgi-&gt;param('data_id');     
  $json = qq{{"ID" : "$id"}};
  
  $cgi-&gt;header(-type =&gt; "application/json", -charset =&gt; "utf-8");
  print $json;
  
  exit;
  </code></pre>