I'm trying to update a single value of a list item in SharePoint 2010 using REST and jQuery. So far, I haven't gotten anything to work. I've looked at many posts and MSDN articles. Here's a link to a post that claims to work, but it fails with "500: Internal Server Error". Below is my version of the code To be clear, I need to do everything from the client, and would prefer to use REST over SPServices method.
<html>
<head>
<script language="javascript" type="text/javascript"
src="https://http://[path removed]/jquery.json-2.4.min.js"></script>
<script language="javascript" type="text/javascript">
//update
function updateProject(id) {
var projectUrl = "http://[path removed]/_vti_bin/listdata.svc/ProjectManagement";
projectUrl = projectUrl + "(" + id+ ")";
var beforeSendFunction;
var projectModifications = {};
projectModifications.Title = "Test Update Performed";
//var updatedProjectData = JSON.stringify(projectModifications);
var updatedProjectData = $.toJSON(projectModifications);
//update exsiting project
beforeSendFunction = function (xhr) {
xhr.setRequestHeader("If-Match", "*");
// Using MERGE so that the entire entity doesn't need to be sent over the wire.
xhr.setRequestHeader("X-HTTP-Method", 'MERGE');
};
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
processData: false,
beforeSend: beforeSendFunction,
url: projectUrl,
data: updatedProjectData,
dataType: "json",
error: function (xhr) {
alert(xhr.status + ": " + xhr.statusText);
},
success: function () {
alert("Updated");
getAll();
}
});
}
</script>
<title>Test Page</title>
</head>
<body>
<div id="divarea">This is a test page</div>
<button onclick="updateProject(2523);">Update!</button>
</body>
</html>