You are not logged in.
Pages: 1
I faced with issue dealing with transmitted JSON content from server to ajax client application.
I have the following code:
type
TPersist = class(TPersistent)
private
FFileName : RawUtf8;
FDisplayName : RawUtf8;
published
property FileName : RawUtf8 read FFileName write FFileName;
property DisplayName : RawUtf8 read FDisplayName write FDisplayName;
end;
TSQLBaby = class(TSQLRecord)
private
fName: RawUTF8;
FPersistField: TPersist;
published
property Name: RawUTF8 read fName write fName;
property PersistField : TPersist read FPersistField write FPersistField ;
end;
p:=TPersist.Create;
Baby.FPersistField := p;
p.FFileName := 'This is file name';
p.FDisplayName := 'This is display name';
Client.Add(Baby,true);
And by going to uri: http://localhost:8080/root/baby/26 I get the following answer:
{"ID":26,"Name":"TEST_COL_LIST","PersistField":"{\"FileName\":\"This is file name\",\"DisplayName\":\"This is display name\"}"}
The issue is that I get PersistField as string"{\"FileName\":\"This is file name\",\"DisplayName\":\"This is display name\"}"} but I want to get a true JSON object.
I found next info in the manual:
Up to revision 1.15 of the framework, the transmitted JSON content was not a true JSON object, but
sent as RawUTF8 TEXT values (i.e. every double-quote (") character is escaped as - e.g.
"UTF8":"[32]"). Starting with revision 1.16 of the framework, the transmitted data is a true JSON
object, to allow better integration with an AJAX client. That is, UTF8 field is transmitted as a valid JSON
array of string, and Persistent as a valid JSON object with nested objects and arrays.
As I understood, since I use version 1.18 I should receive a true json object.
Could you please help me on this issue?
Offline
Your quote is about the transmission from client to the server.
In this case, you can send plain string or an object to the server.
In the other direction ,i.e. transmission to client from the server, if the object is retrieved directly from the database, it may reflects the storage layout, which is a string, depending on the database.
Offline
AJAX clients will now be identified so that /tablename/id would return true JSON, e.g. for nested objects, even if was stored as string or binary.
See http://synopse.info/fossil/info/04598ad7c4
Hope it helps.
Offline
Greate news, thank you very much for a fast fix!
You did this fix for /tablename/id query, is it possible to add this improvement for /tablename/?select=* query also? I would be very grateful if you would do it.
Offline
We have ensured that root/table?select=...&where=... return plain standard JSON output for AJAX clients.
Offline
That's awesome, great thx for that!
And I have one more question, dealing ajax. Is it possible to return some data, for example ID, after POST request?
Offline
Pages: 1