How i can update object in the table?

I read https://backendless.com/documentation/data/js/data_updating_data_objects.htm but I did not find good JS examples. I need to change column “rating” in item of the table. This code is wrong:

var savedItems = Backendless.Persistence.of( Items );
var changeItems =  savedItems.find().data[0].rating = "1";
savedItems.save( changeItems );

and this one also:

$.ajax({

    url: 'https://api.backendless.com/v1/data/Items/08BEF67E-FDDE-61B6-FF66-25EA83E7B300',
    type: 'PUT',
    data: {"rating" : 1}, 
    success: function() { alert('PUT completed'); }
});

“XMLHttpRequest cannot load https://api.backendless.com/v1/data/Items/08BEF67E-FDDE-61B6-FF66-25EA83E7B300. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost’ is therefore not allowed access. The response had HTTP status code 401.”

Im sorry for my low skill. I have not worked with server-side yet. I dont know obout REST, give me examples please.

Hi Eugen,

Here’s a working sample for you (you just need to change APP_ID and SECRET_KEY):

http://jsfiddle.net/backendless/zgeekgnp/

Hope this helps.

Regards,
Mark

Thank you!
This code is also right:


$.ajax({
    url: 'https://api.backendless.com/v1/data/Items/08BEF67E-FDDE-61B6-FF66-25EA83E7B300',
    type: 'PUT',
	headers: {
        'application-id':"2C9C3B50-FE23-FA0F-FFE1-222ADFEDD600",
        'secret-key':"F2B0F631-68E6-4F9B-FF9C-01B923F63500",
    },
	contentType: "application/json; charset=utf-8",
    data: '{"rating":2}',
	crossDomain: true,
	dataType: 'json',
    success: function() { alert('PUT completed'); }
});