I'm trying to do a simple update in my MySQL database, I have created a REST service using JPA. The problem is, I don't know where to put the "name/value", the data that I want to use to update the column in the specific row, I think I'm supposed to be using ajax to do this, but I have no idea how. Please herp!

for example if I want to update the column named "comment" which has id "1" I'd do like this in Google Chrome REST Client Extension :

URL: http://example.com/api/accounts/1

And choose the PUT method

and as body:

"comment": "The Test Comment"

And it works. Now my question is, how do I do this in a SharePoint-Hosted App ( javascript)

All I want to be able to do, is updating the comment in my remote REST service using the REST PUT method and a value from a textbox.

This is the Ajax I've tried so far:

    type: 'POST',
    dataType: 'json',
    contentType: 'application/json', 
    url: "http://example.com/_api/clients/1",
    headers: { "X-HTTP-Method-Override": "PUT" },
    data: '{"comment": "Dave"}'


  • I am not sure if this is gonna help, but you can use method:POST and in header add this line X-HTTP-Method: PUT Sep 15, 2015 at 13:50

1 Answer 1


I had to use SP.Webproxy, as It's a cross domain call & sharepoint is http(s) and my remote web service was a regular (http).

Here's the code I used to make it work:

function RESTPUTCOMMENT(e) {
var newComment = document.getElementById("txtAddComment").value;
var dataObject = { 'comment': newComment }
var context = SP.ClientContext.get_current();
var request = new SP.WebRequestInfo();
var response = SP.WebProxy.invoke(context, request);

request.set_url("http://example.com/_api/accounts/" + commentId);
request.set_headers({ "Content-Type": "application/json; charset=utf-8" });

context.executeQueryAsync(successHandler, errorHandler);


function successHandler() {
function errorHandler() {

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.