Using a WFS-Transaction service usually requires less server-side configuration, but more considerations on the client side. OpenLayers 3 can write WFS-T requests; however, it is hard coded to support only Version 1.1.0. We can create a minimalistic WFS-T request with the following code:
var WFSTSerializer = new ol.format.WFS();
var featObject = WFSTSerializer.writeTransaction(this.getFeatures(), null, null, {
featureType: 'ne:countries',
featureNS: 'http://naturalearthdata.com',
srsName: 'EPSG:3857'
});
var serializer = new XMLSerializer();
var featString = serializer.serializeToString(featObject);
var request = new XMLHttpRequest();
request.open('POST', 'myowsserver?SERVICE=WFS');
request.setRequestHeader('Content-Type', 'text/xml');
request.send(featString);As WFS-T services can insert, update, and delete features with POST, the writeTransaction method requires three arrays of features (insert, update, and delete). It also needs some options regarding the GML schema the method has to use. The method returns an XML node that needs to be serialized and then we can send it to the server. We also have to notify the server; we send XML data in the request body, by setting a Content-Type header.