title: AJAX JSON RPC ERROR: [object Object]
body: <p>I am trying to call a JSON RPC function via CGI with perl. But getting the following error.</p>
  
  <blockquote>
    <blockquote>
      <p>ERROR: [object Object</p>
    </blockquote>
  </blockquote>
  
  <p>Can someone please help me on this? Thanks in advance.</p>
  
  <p><strong>Test.html</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="http://code.jquery.com/jquery-1.11.0.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  $(document).ready(function() {
  
                                  $.ajax({
                                          type: "POST",
                                          url: "cgi-bin/server.cgi",
                                          data: '{"version": "1.1", "method": "echo", "params" : ["Hello World"]}',
                                          processData: false,
                                          async: false,
                                          timeout: 30000, // msec
                                          contentType: "application/json",
                                          dataType: "json",
                                          success: function(response){
                                                  $("body").append( "&lt;br&gt;SUCCESS: " + response.version );
                                                  $("body").append( "&lt;br&gt;version: " + response.version );
                                                  $("body").append( "&lt;br&gt;result: " + response.result );
                                                  $("body").append( "&lt;br&gt;OK" );
                                          },
                                          error: function(response){
                                                  $("body").append( "ERROR: " + response );
                                                  $("body").append( "&lt;br&gt;" );
                                          }
                                  });
  
  
  });
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>server.cgi</strong> </p>
  
  <p>[root@ip-172-31-0-164 cgi-bin]# cat server.cgi 
      #!/usr/bin/perl</p>
  
  <pre><code>use JSON::RPC::Server::CGI;
  use strict;
  
  my $server = JSON::RPC::Server::CGI-&gt;new;
  
  $server-&gt;dispatch('MyApp')-&gt;handle();
  </code></pre>
  
  <p><strong>MyApp.pm</strong></p>
  
  <pre><code>[root@ip-172-31-0-164 cgi-bin]# cat MyApp.pm 
  #!/usr/bin/perl
  
  package MyApp;
  
  use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than
  use strict;
  
  sub echo : Public {    # new version style. called by clients
       # first argument is JSON::RPC::Server object.
       return $_[1];
  
  }
  
  sub sum : Public(a:num, b:num) { # sets value into object member a, b.
       my ($s, $obj) = @_;
       # return a scalar value or a hashref or an arryaref.
       return $obj-&gt;{a} + $obj-&gt;{b};
  }
  
  1;
  </code></pre>