[SOLVED] REST PUT not working

I am writing my own custom webpage and i’m reading item state with Openhab API which is very good but when i try to PUT a new temperature setpoint it does not work.

Here is my JavaScript jQuery code

$("#settemp").click(function() {
    console.log("Gumb pritisnjen");
    var request = $.ajax
    ({
        type       : "PUT",
        url        : "http://localhost:8080/rest/items/termostat1_zelena_temperatura/state",
        data       : '28', 
        headers    : { "Content-Type": "text/plain" }
    });
    
    request.done( function(data) 
    { 
        console.log( "Success" );
    });
    
    request.fail( function(jqXHR, textStatus ) 
    { 
        console.log( "Failure: " + textStatus );
    });
});

In chrome console i get parsererror.

Like you I have custom webpage as dashboard. I use this:

var request = $.ajax
				({
					timeout		:	10000,
					type       	: 	"PUT",
					url        	: 	OHServer+"rest/items/GoodNight/state",
					data       	: 	txtNewState, 
					headers    	: 	{"Content-Type": "text/plain", "Accept": "application/json"},
					dataType	:	"text"
				});

Hope it helps.

It still does not work.

When i send fixed value like data : ‘25’, then PUT request works just fine but when i give a variable instead it returns Bad Request.

I had to convert number to string in JavaScript and then Openhab API server accepts new value.