#1 2012-11-25 23:03:28

rdufour
Member
Registered: 2012-11-24
Posts: 1

Server -> Delphi Rest Web Service, Client -> Javascript

I've tried the demo Rest web Service server/client written in Delphi. So, Ok, the "Delphi" client can connect to the "Delphi" server. Can someone PLEASE post an example of connecting to the Delphi Rest Web Service (server) using "Javascript"?

I am simply trying to execute the example "Sum" function that is found in the demo server.

This is what I have (my server listens on port 8089): All I get is a Error: Timeout: Undefined.

<JAVASCRIPT>
      var dataObj = {};
      dataObj['A'] = '1';
      dataObj['B'] = '2';

      $.ajax({
        url: 'http://localhost:8089/Sum',
        type: 'GET',
        data: dataObj,
        contenttype: 'application/json; charset=utf-8',
        dataType: 'jsonp',
        timeout: 10000,
        success: function(data, textStatus, jqXHR){
            alert(textStatus);
          $('#the_result').val( data.name );
        },
        error: function(jqXHR, textStatus, errorThrown){
            alert('Error:'+textStatus+': '+errorThrown+'\n'+jqXHR.responseText );
        },
        jsonpCallback: 'JsonpCallback'
      });
    }
</JAVASCRIPT>

A lot of posts mention how easy it is to use morMot, however, I've been spinning my wheels for days, "Googled" half a million pages, and cannot seem to find the answer.

Any help would be very much appreciated.

Richard

Offline

#2 2012-11-26 08:25:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Server -> Delphi Rest Web Service, Client -> Javascript

In mORMot interface-based services uses GET or POST methods, depending on the routing scheme.
They expect URL-level authentication to work, for security reasons.
JSONP callbacks are not handled yet - it is on the roadmap.

Not worth reading half a million Google result.
Open the documentation, the Software Architecture Document.
Search "JavaScript" in the keywords index at the beginning of it.
Click on the bold+underlined link - this is the main entry about this subject.
That is, title is "Authentication using AJAX".

Authentication using AJAX
Some working JavaScript code has been published in our forum by a framework user (thanks, "RangerX"), which implements the authentication schema as detailed above. It uses jQuery, and HTML 5 LocalStorage, not cookies, for storing session information on the Client side.
See http://synopse.info/forum/viewtopic.php?pid=2995#p2995..

The current revision of the framework contains the code as expected by this JavaScript code - especially the results encoded as JSON (page 124) objects.

In the future, some "official" code will be available for such AJAX clients. It will probably rely on pure-pascal implementation using such an Object-Pascal-to-JavaScript compiler - it does definitively make sense to have Delphi-like code on the client side, not to break the ORM design. For instance, the Open Source DWS (DelphiWebScript) compiler matches our needs - see http://delphitools.info/tag/javascript..

You will find the following link on our forum:
http://synopse.info/forum/viewtopic.php?pid=2995#p2995
Here is some sample code.

So there is yet no "official" AJAX client code.
Some users shared their own code, which works on production.
You are welcome to contribute here!

Offline

Board footer

Powered by FluxBB