0

I have created a Datasnap REST server.
A ReverseString method gets created by default that simply reverses the string passed to the method.

When I invoke the method using the browser URL:

http://dummydomain.com:81/datasnap/rest/TServerMethods1/ReverseString/ABC

I receive {"result":["CBA"]} as result. (server runs on port 81 and the parameter passed to the method is ABC)

I have tried the following code to get the result into a variable in javascript, but without success:

var options={
  type: "GET",
  url: "http://dummydomain.com:81/datasnap/rest/TServerMethods1/SayHello",
  data: "ABC",
  dataType: "json",
  success: function(data) {
    var json = JSON.stringify(data);
    $("p").after('<div id="data1">Your result is: ' + json.result + '</div>');
    }
}
$.ajax(options);

What am I doing wrong? In the end I need 'CBA' in a variable. If there are some good resources out there, please advise. I have been googling but everybody seem to do it in their own way.

Sir Rufo
  • 16,671
  • 2
  • 33
  • 66
Odione
  • 5
  • 3
  • Have you tried debugging with REST Client addon in Firefox. https://addons.mozilla.org/en-US/firefox/addon/restclient/ You may be missing content type headers. – Ertunç Jan 13 '14 at 19:36
  • Hi Ertunç, thank you for advising the REST Client addon. It works pretty cool. When I use it I get the following response headers: 'code' Status Code: 200 OK Connection: close Content-Length: 18 Content-Type: text/html; charset=ISO-8859-1 Date: Tue, 14 Jan 2014 07:49:43 GMT Pragma: dssession=670648.436193.624911,dssessionexpires=1200000 `code` and in all 3 of the response body tabs I get {"result":["CBA"]} which is expected. How should I format the JSON that will be sent to the webservice? – Odione Jan 14 '14 at 07:50
  • I don't know how you achieve it with Delphi but have a look at this for correct headers for returning JSON http://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type – Ertunç Jan 14 '14 at 10:17

0 Answers0