indiWiz.com

Subhash's Tech Log

Accessing RESTful WebServices with Prototype.js

without comments

We can make Ajax requests using Prototype.js (version 1.6.0.3) thus:

var url = ...;
new Ajax.Request(
            url,
            {
               method:'DELETE',
               onComplete:function doMessage(response){
                   alert(response.status);
               }
            });

While working on this code, we found out that the method parameter accepted only GET or POST requests. When we give any other request type like DELETE or PUT, the Prototype.js library converted the request to POST.

Arun Jeganath found this post where the same issue is discussed. The problem was solved when we commented these lines from the Prototype.js code:

      if (!['get', 'post'].include(this.method)) {
        //simulate other verbs over post
        params['_method'] = this.method;
        this.method = 'post';
      }

Written by Subhash Chandran

July 22nd, 2009 at 7:30 am

Posted in Scripting

Tagged with , , ,

Leave a Reply