0

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?

2 Answers 2

5

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() { }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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!');
    }
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.