1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default Ext Direct API throws You're trying to decode an invalid JSON String:

    Ext Direct API throws You're trying to decode an invalid JSON String:


    Hello,

    When I attempt to set up an Ext Direct API setting in the designer, I get this error box and the Ext Direct setup does not work.

    You're trying to decode an invalid JSON String: Ext.ns('Ext.app'); Ext.app.REMOTING_API = { "url" : "/demo/controller/router", "type" : "remoting", "actions" : { "namedService" : [ { "name" : "showDetails", "params" : [ "firstName", "lastName", "age" ] } ] } };

    Source Class: Ext.JSON
    Source Method: decode

    The really strange thing is that this is occurring ONLY when I attempt to make the request to my localhost, When I attempt to connect to
    http://extdirectspring.ralscha.ch/demo/controller/api-debug.js?group=named

    It works.


  2. #2
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default Discovered issue

    Discovered issue


    Right after I posted I discovered the issue.

    Apparently there's an undocumented (at least as far as I can tell) format=json parameter that is automatically added to the request by Designer.

    Designer then expects the following format for the json response.

    { "descriptor" : "Ext.app.REMOTING_API", "url" : "http://localhost:8080/demo/controller/router", "type" : "remoting", "actions" : { "namedService" : [ { "name" : "showDetails", "params" : [ "firstName", "lastName", "age" ] } ] }}I did eventually find a reference to this in the forum as well, and it says:
    "If your Ext Direct router does not support the format=json parameter, then it is not following the recommended spec"
    I searched everywhere I could to find a spec on this and there doesn't seem to be any documentation on it. Also it's not the router component that needs to accept the format parameter it's the API component.

    Hopefully, this will be documented better soon. This documentation, which is the only official documentation I can find, doesn't say anything about the "format" parameter.
    http://www.sencha.com/products/extjs/extdirect

  3. #3
    Sencha - Architect Dev Team Phil.Strong's Avatar
    Join Date
    Mar 2007
    Location
    Olney, MD
    Posts
    1,919
    Vote Rating
    63
    Phil.Strong is just really nice Phil.Strong is just really nice Phil.Strong is just really nice Phil.Strong is just really nice

      0  

    Default


    Well isn't it also because by default we give your Direct Store a JSON reader. You can transform this into an xml or array reader as well.
    Phil Strong
    @philstrong
    #SenchaArchitect
    Sencha Architect Development Team

  4. #4
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default


    Hi Phil,

    No this was actually in the Designer itself not in the Store. When you give Designer an API destination (Project Settings/Ext Direct API), Designer makes a call to the API and expects it to return the API definition in a JSON response not as a javascript response like it shows in the http://www.sencha.com/products/extjs/extdirect documentation. So this is before the store is even defined or any use of Direct is attempted.

    Once the designer has the API definition it correctly resolves the api config object in the Direct Store. and the directFn config option shows the dropdown of choices properly as well.

    To reproduce, change your server API controller to return only the javascript version of the API like it shows in the API section of the documentation. (Note this will mean turning off the format='json' parameter handling since the Designer adds that parameter automatically).

    Ext.app.REMOTING_API = { "url":"remote\/router.php", "type":"remoting", "actions":{ "AlbumList":[{ "name":"getAll", "len":0 },{ "name":"add", "len":1 }] }};
    Instead of this format:

    { "descriptor" : "Ext.app.REMOTING_API",
    "url" : "remote/router.php",
    "type" : "remoting",
    "actions" : {
    "AlbumList" : [
    {
    "name" : "getAll",
    "len" :0},
    { "name":"add",
    "len":1
    }
    ]
    }}


    Then change the API definition in the project settings of designer and save. The error should occur immediately.

    Thanks
    Bob

  5. #5
    Sencha - Architect Dev Team Phil.Strong's Avatar
    Join Date
    Mar 2007
    Location
    Olney, MD
    Posts
    1,919
    Vote Rating
    63
    Phil.Strong is just really nice Phil.Strong is just really nice Phil.Strong is just really nice Phil.Strong is just really nice

      0  

    Default


    Ah this is more clear now thank you! Bharat has been working hard over the last week updating Direct in Designer so I'm going to let him update here. Seems like an oversight.
    Phil Strong
    @philstrong
    #SenchaArchitect
    Sencha Architect Development Team

  6. #6
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default


    Cool, makes sense as an oversight. Just wanted to give you guys as much info as possible so the docs can be updated.

    Thanks
    Bob

  7. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    350
    Vote Rating
    1
    bharatn is on a distinguished road

      0  

    Default


    Hi Bob,

    The api.php does return javascript. I am using standard Ext 4 example which returns


    Ext.ns("Ext.app"); Ext.app.REMOTING_API = {"url":"php\/router.php","type":"remoting","actions":{"TestAction":[{"name":"doEcho","len":1},{"name":"multiply","len":1},{"name":"getTree","len":1},{"name":"getGrid","len":1},{"name":"showDetails","params":["firstName","lastName","age"]}],"Profile":[{"name":"getBasicInfo","len":2},{"name":"getPhoneInfo","len":1},{"name":"getLocationInfo","len":1},{"name":"updateBasicInfo","len":0,"formHandler":true}]}};

    Thanks
    Bharat Nagwani
    Sencha Designer Development Team

  8. #8
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default


    Hi Bharat,

    Yep, but, if you add a parameter of format=json to your request, the API is apparently supposed to return a json version which is slightly different.

    Sencha Designer, automatically adds this parameter to the URL you give it when defining your ext direct setup, and my server didn't know to respond with json for the API definition in this case so Designer threw the error when it tried to parse the javascript API definition as a json object.

    Now that I know about the format parameter, I've been able to use Designer just fine. The parameter should be added to the API documentation http://www.sencha.com/products/extjs/extdirect since there's no mention of a format parameter in the API section (or anywhere on that page).Also it should be noted in the Designer help to say that the designer will automatically make the Ext Direct API configuration request using the format=json parameter.

    Thanks guys,
    Bob


  9. #9
    Ext JS Premium Member
    Join Date
    Sep 2010
    Posts
    364
    Vote Rating
    6
    stewardsencha is on a distinguished road

      0  

    Default


    For php see http://www.sencha.com/forum/showthre...ation-with-PHP

    That class is pretty sweet and handles it automagically.

    But when I plug the url into the designer (architecturer?) I get red squiggles. No message. Yet this is a working url. If I plop it into a browser I get the expected json. And my app uses it fine.

    By playing around I can get a message to flicker "Ext Remoting specification failed to load". At this point I might inspect the network tab... do you have a console window (heh heh)?

    In case it suggests anything, the generated html is
    Code:
            Ext.ns("");
             = {"url":"http://mysite.dev/index.php/direct/crud/service/vmaster","type":"remoting","actions":{"CrudService":[{"name":"read","len":0},{"name":"update","len":0},{"name":"destroy","len":0},{"name":"GridView","len":1},{"name":"where","len":2}]}};
            Ext.Direct.addProvider();
    Also I wonder about how to make the designer aware of additional remoting providers.


    I love this tool guys, I ache for it. But it sucks the hours away every bit as much as the core.

  10. #10
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    badgerb1 is on a distinguished road

      0  

    Default


    Hi Steward,

    Had much the same problem with our in house generated API. The problem is probably because the format of the file returned by your php isn't the json version. To test this in a browser, put your URL that you are trying to connect to into the browser and add format=json at the end of it (designer adds this by default and you don't know it).

    The designer expects a pure json. So make sure this is all that gets returned by the API when it has the format=json added to it. It can't have the Ext.ns("") or the Ext.Direct.addProvider(); portions and the json has to include the "descriptor" as is shown below.

    { "descriptor" : "Ext.app.REMOTING_API",
    "url" : "remote/router.php",
    "type" : "remoting",
    "actions" : {
    "AlbumList" : [
    {
    "name" : "getAll",
    "len" :0},
    { "name":"add",
    "len":1
    }
    ]
    }}


    Thanks
    Bob