title: How do I PUT JSON data to Ruby on Rails using jQuery?
body: <p>I am trying to send a jQuery Ajax PUT request that looks like this:</p>
  
  <pre><code>$.ajax({
        type: "PUT",
        url: '/admin/pages/1.json',
        data: { page : {...} },
        dataType: 'json',
        success: function(msg) {
          alert( "Data Saved: " + msg );
        }
  });
  </code></pre>
  
  <p>My controller looks roughly like this:</p>
  
  <pre><code>      respond_to do |format|
           if @page.update_attributes params[:page]
             format.html{ ... }
             format.json{ render :json =&gt; {:saved =&gt; 'ok'}.to_json }
           else
             format.html{ ... }
             format.json{ render :json =&gt; {:saved =&gt; 'fail'}.to_json }
           end
         end
  </code></pre>
  
  <p>but I get the following error.</p>
  
  <p>The error occurred while evaluating nil.name
      /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:29:in <code>merge_element!'
      /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:18:in</code>parse'
      (<strong>DELEGATION</strong>):2:in <code>__send__'
      (__DELEGATION__):2:in</code>parse'
      /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/hash/conversions.rb:154:in `from_xml'
  ...
  ...</p>
  
  <p>It is like Ruby on Rails is trying to parse the parameters as XML, but I want to use JSON!</p>
  
  <p>What shall I do to put JSON to Ruby on Rails?</p>