views:

63

answers:

2

There is currently this Prototype code that does a PUT:

new Ajax.Request(someUrl, {
    method: 'put',
    parameters: { 'foo': bar },
    onSuccess: function(response) { } .bind(this)
});

I found this post but the solution uses an extra parameter supported by RoR, however I am targeting an ASP.NET backend.

I searched a bit and found that not all browsers support PUT operations so apparently this could fail in certain browsers? This is already in prod, so a direct port would be fine for now I suppose.

As an aside, what is the deal with the bind(this) in the onSuccess function?

A: 

put and delete requests map to the jQuery $.ajax function (here).

$.ajax(
    url: someUrl,
    type: 'put',
    data: { /* your key-value data pairs here */ },
    success: function() {
        alert('put request succeeded!');
    }
);
Jarrett Meyer
+5  A: 

The .bind(this) returns a wrapper function that calls the original function in the context of the parameter passed to .bind.

You can port the code using $.ajax:

$.ajax({
    url: someUrl,
    type: 'put',
    data: { foo: bar},
    context: this,        //Calls callback in context.
    success: function() { }
});
SLaks