title: Is it really possible to call HTTP PUT using prototype
body: <p>I'm running <code>JEE6</code> with <code>glassfish v3</code> on <code>NetBean6.9</code> and working on <code>RESTful web service</code>.</p>
  
  <p>I have jsp file which contains javascript function below.</p>
  
  <p>It basically read info from <code>HTML input fields</code> and convert to <code>JSON format</code>.</p>
  
  <p>Then with <code>onclick Ajax call</code>, <strong>attempt to send JSON string using HTTP PUT method</strong>.
  (i.e. I'm trying to <code>UPDATE</code> the db record using REST)</p>
  
  <p>For js framework I'm using is <code>Prototype1.7</code></p>
  
  <p>When I test the function below, it always return 404 thus "something went wrong" alert is displayed.</p>
  
  <p>According to my search Prototype above 1.5 version supports HTTP PUT/DELETE methods and to do so add <strong>_method</strong> to the request URL like what I'm doing:</p>
  
  <pre><code>var url = "/resources/inventory/" + invId + "?_method=PUT";
  </code></pre>
  
  <p>This will create for instance:</p>
  
  <pre><code>http://localhost:8080/NoJSF/resources/inventory/123?_method=PUT
  </code></pre>
  
  <p>I looked at Firebug and console showing that the request is actually <strong>POST</strong>. Not sure but I believe this is because of Prototype using POST tunneling to achieve PUT method?</p>
  
  <p>Also even though Ajax is being called, my Java file with JAX-RS annotated witn @POST is not even being called (@GET version is working with separate data so this is the right file) since the first line of its method that spit message is not showing up so I suspect my Ajax statement has some bug or there is something beyond my thinking.. could anyone give me hint?</p>
  
  <pre><code>function protoAjaxPut() {
              //get all fields value and store into json
              var invId = document.getElementById("invIdField").value;
              var invName = document.getElementById("invNameField").value;
              //put info into JSON format
  
              var jsonInput = JSON.stringify(new Array(invName));
  
              var url = "/resources/inventory/" + invId + "?_method=PUT";
  
              new Ajax.Request(url, {
                  method:'put',
                  postBody: jsonInput,
                  ContentType: 'application/json',
                  onSuccess: function(transport) {
                      var responseData = transport.responseText;
                      document.getElementById('putResponseText').innerHTML = responseData;
                  },
                  onFailure: function() { alert('something went wrong!')}
              })
          }//end protoAjaxPut
  </code></pre>