I don't really use dojo.xhr too often to do my CRUD, but it should look similar to this.
updateData = function(graphic) {
var _args, attr, data, geom;
attr = graphic.attributes;
// JSON methods may not be available in all browsers
// I think dojo.toJson(obj).toString() will
// do the same thing.
geom = JSON.stringify(graphic.geometry.toJson());
data = {
"Geometry": geom
};
_args = {
// my .net service will handle the writing
// to sql server
url: "api/service/" + attr.id,
postData: data,
handleAs: "json"
};
// I think you'd use xhrRawPost for json data,
// I'm not clear on this one.
return dojo.xhrRawPost(_args);
};
Then to read the updated data at a later time.
graphics = []; // array that will hold my graphics
// results would be the response from
// from a REST request via dojo xhr or jquery ajax
dojo.forEach(results, function(result) {
var g, res_geom, res_obj;
// result is JSON, but Geometry is a string field
// convert string field to JSON object
res_obj = dojo.fromJson(result.Geometry);
// convert json to geometry
res_geom = esri.geometry.fromJson(res_obj);
//create my graphic
g = new esri.Graphic(res_geom, symbolHelper.lineSymbol(), {
"Id": attribute.Id,
"WorkOrderId": attribute.WorkOrderId
});
return graphics.push(g);
});
// In this case, I update a FeatureLayer, but you can easily just add
// graphics to a GraphicsLayer
prev_graphics = lineFeatures.graphics;
lineFeatures.applyEdits(graphics, null, prev_graphics);
Hope that helps a bit, I tweaked some stuff from a project for this example to simplify it a bit, but not too much.