ptalbot:
Well formed XML has usually only one root element. In your case it is missing…
I suppose you are returning an array, but I think the rest_ws plugin is expecting an object, so maybe you should encapsulate your array inside a simple object in your ws_ method, something like:
var obj = {root: myArray};
return obj;
Hi Patrick
I thought it would be useful to continue this thread as I am sure others would use the outcome. I have tested restful against the Servoy demo app which is how I got the previous example - so that is the result of the demo. I have put in a trial script to simply return to the console what Servoy is outputting and got:
Servoy Console
{id:6,firstName:Michael,lastName:Suyama}
Firefox Input:
http://localhost:8080/servoy-service/re … mployees/6
Firefox Console:
Error: junk after document element
Source File: http://localhost:8080/servoy-service/re … mployees/6
Line: 2, Column: 11
Source Code:
6SuyamaMichael
Servoy Function - as per Servoy Resful Demo
function ws_read(id)
{
if (id)
{
// read 1 employee
if (foundset.find())
{
foundset.employeeid = id
if (foundset.search() == 1)
{
var emp = new Object()
emp.id = foundset.employeeid
emp.firstName = foundset.firstname
emp.lastName = foundset.lastname
return emp // response body
}
}
}
else
{
// list employee ids
foundset.sort("employeeid asc")
if (foundset.loadAllRecords())
{
var empids = new Array()
for (i = 1; i <= foundset.getSize(); i++)
{
empids[i] = foundset.getRecord(i).employeeid
}
return empids // response body
}
}
// not found or cannot search
return null;
}
…and finally I am trying to call it with and $.ajax call
$.ajax({url:‘http://localhost:8080/servoy-service/rest_ws/servoy_sample_rest_ws/ws_employees/’,
//dataType:‘JSON’,
success: function(data) {
alert(‘success’);
},
error: function(){
alert(‘fail’);
}
});
So overall what I think is going on here is what is being fed into the restful plugin in an object which is in turn formatted as JSON if viewed in the Servoy Console. When this is parsed by the browser its converted to what looks like XML with the tail missing. I have tried a number of approaches to fix this and thus far its bouncing off. The reason I think this would be generally useful is IF it could be made to work then those wishing to use apps like JQuery, JQMobile and JQTouch would be able to get Servoy to handle the data and the JQ to deal with the UI.
Cheers
Gordon