1. #1
    Ext User
    Join Date
    May 2009
    Posts
    5
    Vote Rating
    0
    jean_marie is on a distinguished road

      0  

    Default [SOLVED] Can not call API action in JavaScript

    [SOLVED] Can not call API action in JavaScript


    Hi,

    i'm exploring Ext.Direct and stumble when calling the API actions in JavaScript. I'm using this PHP stack http://extjs.com/forum/showthread.php?t=68186.

    On server side i have coma_api.php which runs this code after all the default stuff:

    PHP Code:
    $api = new ExtDirect_API();

    $api->setRouterUrl('coma_router.php'); // default
    $api->setNamespace('Ext.app');
    $api->setDescriptor('Ext.app.REMOTING_API');

    $api->add(
        array(
        
    'COMA_API_ViewHandler'
        
    )
    );
    ... 
    Within my test index.php i have this at the end of the file:
    HTML Code:
        <script type="text/javascript" src="coma_api.php"></script>
        <script type="text/javascript">
            window.onload = function(){
                Ext.Direct.addProvider(Ext.app.REMOTING_API);
    
                COMA_API_ViewHandler.getUI(function(provider, response){
                    alert('tell todd');
                });
            };
        </script>    
    When i open index.php Firebug tells me:

    Code:
    Ext.ns('Ext.app');
    Ext.app.REMOTING_API = {"url":"coma_router.php","type":"remoting","actions":{"COMA_API_ViewHandler":[{"name":"getUI","len":0,"serverMethod":"getUI"}]},"namespace":"Ext.app"};
    But calling COMA_API_ViewHandler gives me an JS error:
    HTML Code:
    Fehler: COMA_API_ViewHandler is not defined
    Quelldatei: https://myserver/index.php
    Zeile: 46
    What i'm doing wrong? Do i miss anything?

    Thanks in advance and best regards,
    Jean Marie
    Last edited by jean_marie; 2 Jun 2009 at 1:10 AM. Reason: solved

  2. #2
    Ext JS Premium Member stever's Avatar
    Join Date
    Mar 2007
    Posts
    1,377
    Vote Rating
    1
    stever will become famous soon enough

      0  

    Default


    Off the top of my head, have you tried Ext.app.COMA_API_ViewHandler.getUI?

  3. #3
    Ext User
    Join Date
    May 2009
    Posts
    5
    Vote Rating
    0
    jean_marie is on a distinguished road

      0  

    Default


    Thanks, using the defined namespace makes sense and works!

    When i
    HTML Code:
    console.log(Ext.app);
    Firebug tells me:
    firebug_ext.direct.jpg

    I ran into this error because i followed the official Ext.Direct description (http://extjs.com/products/extjs/direct.php). See chapter Client Side portions of Ext.Direct:

    HTML Code:
    Ext.Direct.addProvider(Ext.app.REMOTING_API);
    AlbumList.getAll(function(provider, response) {
     // process response
    });
    ???

    Thanks and best regards,
    Jean Marie

  4. #4
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    8,189
    Vote Rating
    63
    aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice

      0  

    Default


    Jean Marie -

    If you specified no namespace your client-side stubs would have been generated in the window namespace. Because you specified "Ext.app", they are available there.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  5. #5
    Ext User
    Join Date
    May 2009
    Posts
    5
    Vote Rating
    0
    jean_marie is on a distinguished road

      0  

    Default


    Quote Originally Posted by aconran View Post
    Because you specified "Ext.app", they are available there.
    100% ;-). I got it.

    I tried it without specifying the namespace on server side within the PHP stack implementation and than it works like the documentation example.

    But i would prefer the namespace variant.

    Thanks and best regards,
    Jean Marie