Creating nodes with services module

Submitted on Wed, 11/23/2011 - 13:14

So, today i decided to have a go at the services module, to make an app post nodes to my site. With services module enabled you can do a number of things from non-drupal sites, for example you can post nodes through your phonegap app by javascript. And that is exactly what i wanted to do today.

Ok here is the javascript code, the services part of it is pretty straight forward to set up anyway, but finding how to create nodes with json and javascript was not that easy. You can probably figure out how to log in based on this, and this snippet posts to a content type with a geofield, and posts the users location onto my server, along with some other values.

eiriksm/413ecfc181032e6f6fa4

Remember, in phonegap, this should be fired when phonegap has loaded! Also, this entire thing is wrapped in the geolocation success function, just for shorter code. You probably want to have this as a named function, as well as an error function