title: jQuery and Rails ajax request and response
body: <p>Trying the basic stuff,</p>
  
  <p>request with data and response with data and print it with jQuery and Rails</p>
  
  <p>This is the front code.</p>
  
  <pre><code>$("#internal_btn").click(function() {
              //window.alert("clicked internal btn!");
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  url: "/room/test",
                  //data: "{'data1':'" + value1+ "', 'data2':'" + value2+ "', 'data3':'" + value3+ "'}",
                  data: {name:"ravi",age:"31"},
                  dataType: "json",
                  success: function (result) {
                  //do somthing here
                      window.alert("success!!");
                  },
                  error: function (){
                      window.alert("something wrong!");
                  }
              });
          });
  </code></pre>
  
  <p>in here, if the user clicks internal_btn this event happens and goes to the servide</p>
  
  <p>room/test action.</p>
  
  <p>ok this is fine. But I'm not sure how to send the data.</p>
  
  <p>If i run this, i have an error like this.</p>
  
  <pre><code>MultiJson::LoadError
  
  795: unexpected token at 'name=ravi&amp;age=31'
  </code></pre>
  
  <p>Can i know what the problem is?</p>
  
  <p>Also, is there are good example with this request and response with json format?</p>
  
  <p>I googled a lot, but not satisfied with the result :(</p>