RESTful Web Services return value

Hi all,

I’m getting error with RESTful by returning an object with more than 1 property.

ex:

var _obj = new Object()
     _obj.id = 1
return _obj

works fine, into the response body I get an xml with a key “ID” and a value “1”.

var _obj = new Object()
     _obj.id = 1
     _obj.myName = "Marco"
return _obj

Gives the error shown within the picture attached.
[attachment=0]error.png[/attachment]

Am I missing something?

Regards

Marco

Your browser is complaining because the result isn’t valid xml, because there is no root element.
The xml will be something like 1Marco if you check the page source.

To have a valid xml, wrap your result in a single node, like this:

var _obj = new Object()
_obj.result = new Object()
_obj.result.id = 1
_obj.result.myName = "Marco"
return _obj

Another tip is to use a more declaritive approach using this literal notation as example:

var id = 1;
var myName = 'Marco';

var result = {
	result: {
		id: id, myName: myName
	}
}
	
return result;