node.save with JSON Server

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by timmillwood on May 29, 2009 at 7:39pm

I am using the services module along with JSON server to create an Adobe Air app.

function send_post(){
obj = new Object;
obj.type = "story";
obj.title = $('#new_post').val();
obj.changed = new Date().getTime();
obj.body = "test";
obj.uid = uid;
obj.nid = "0"

console.log(obj);
$.getJSON(service + "?jsoncallback=?", {method: "node.save", sessid: sessid, node: obj}, function(data){
console.log(data);
listposts();

});
}

The above javascript code is being used to create a node, but it is not working. The response back in the console log is "Node not found". I already have views.get, user.login, user.logout and system.connect working in this way, so I think the problem lies in the the object being sent as the node parameter.

Any help would be great.

Thanks
Tim

Comments

I solved the problem. When

Posted by timmillwood on June 3, 2009 at 8:57am

I solved the problem.

When the node object was getting to the "node_service_save" function in the node_service module it was "[object Object]" as a string.

I couldn't find where it was being converted from an object to a string, so I just passed some JSON as a string, and converted it to an array within the "node_service_save" function.

A little hacky, but it works. If I find time I will go back and find out what's going on.

Now thinking this is pretty

Posted by timmillwood on June 3, 2009 at 7:21pm

Now thinking this is pretty obvious, because I am using the jQuery function getJSON, I am sending using get, this is what is causing the object to turn to a string, not sure if there is a way round it.

Related?

Posted by yajnin on July 17, 2009 at 10:23pm

I'm not sure if my issue is related to yours. It sounds a little familiar, though not quite.

If you're JavaScript minded - you may have insights. I wonder if you'd take a quick look at the problem I've posted here

http://groups.drupal.org/node/24372

Currently I'm stabbing in the dark -- but I'm about to sit down and get serious. Let's hope a light turns on somewhere!

Cheers

Gonna give this a shot

Posted by abritez on November 19, 2009 at 7:56pm

Seems i took the same route as ninjay and ended up here. I seem to be having the same issue (http://groups.drupal.org/node/24372#comment-106866). I guess your solution is probably the only one at this time, so i am gonna give it a shot. Thanks!

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /