In order to achieve this on Drupal 7, you need to develop a custom module that does the following:
Register a menu hook that will act as the endpoint where your javascript will send the data for the node to be created.
Create a function that will be the callback of the hook and handle the actual creating and saving of the node. It can be something like this as mentioned in the answer above:
$data = json_decode($_REQUEST['title']);
$node = new stdClass;
$node->type = 'article';
$node->title = check_plain($data->title);
node_save($node);
echo json_encode(array('Status' => 'OK'));
drupal_exit()
Notice drupal_exit() is needed otherwise you get the whole page rendering.
In order to set other properties for example the body, you need to know the structure, it is usually something like
$node->fieldName[language][delta]['value'] eg, $node->body['und'][0]['value']
That's all it needs on the php side, now on the javascript side you will be needing to create an array containing the values for the node and submit it via ajax. Using jQuery it can be done like this:
jQuery.ajax(
{
url: Drupal.settings.basePath + queryPath,
type: 'POST',
dataType: 'json',
data: {'data': JSON.stringify(queryParameters)},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data)
{
console.log(data);
}
});
Data can contain anything returned from php...
Have fun
Update:
A more general and concrete solution is available through the use of the Services module that allows you to define a REST api over the various content types you create. This way you don't need to write any custom code on the php side,
nid
as the parameter instead and then load the node, populate it and the save it usingnode_save()