Results 1 to 4 of 4

Thread: Restful post missing brackets on single record

  1. #1
    Sencha Premium Member
    Join Date
    Apr 2013
    Posts
    16
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: Restful post missing brackets on single record

    I'm in the very early stages of developing an app. I'm using a store that calls a restful web services API, which I'm also writing... The issue I'm having is this - when I send a single record, brackets seem to be missing from the JSON that is sent back to the php code. The root on the model is "ERRORLOGS"

    For example:
    logStore.add(
    Ext.create('Tim3.model.Log', {
    "LOGIN": "shaleth",
    "PROC_NAME": "MyProc",
    "ERR_MSG": "logging test"
    })
    );
    logStore.sync({
    success: function(){ console.log('success'); },
    failure: function(){ console.log('failure'); },
    scope: this
    });
    sends:
    {"ERRORLOGS":{"LOGIN":"shaleth","PROC_NAME":"MyProc","ERR_MSG":"logging test"}}

    When I add a second record to the store and then sync, it works correctly:

    logStore.add(
    Ext.create('Tim3.model.Log', {
    "LOGIN": "shaleth",
    "PROC_NAME": "MyProc",
    "ERR_MSG": "logging test"
    })
    );
    logStore.add(
    Ext.create('Tim3.model.Log', {
    "LOGIN": "shaleth",
    "PROC_NAME": "MyProc",
    "ERR_MSG": "another logging test"
    })
    );
    logStore.sync({
    success: function(){ console.log('success'); },
    failure: function(){ console.log('failure'); },
    scope: this
    });
    returns:
    {"ERRORLOGS":[{"LOGIN":"shaleth","PROC_NAME":"MyProc","ERR_MSG":"logging test"},{"LOGIN":"shaleth","PROC_NAME":"MyProc","ERR_MSG":"another logging test"}]}

    Note the brackets starting after the first colon - those are missing in the single record example. PHP barks on the single record example - json_decode handles the two situations very differently. What am I missing here? Is this expected behavior?

  2. This is expected behavior. If you want to submit even single records as an array, you should set allowSingle: true on your writer: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.writer.Json-cfg-allowSingle

    H
    ope this helps!

  3. #2
    Sencha User existdissolve's Avatar
    Join Date
    Jan 2010
    Location
    Kansas
    Posts
    522
    Answers
    32
    Vote Rating
    88
      1  

    Default

    This is expected behavior. If you want to submit even single records as an array, you should set allowSingle: true on your writer: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.writer.Json-cfg-allowSingle

    H
    ope this helps!

  4. #3
    Sencha Premium Member
    Join Date
    Apr 2013
    Posts
    16
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Brilliant - thank you so much! Setting it to false did the trick.

  5. #4
    Sencha User existdissolve's Avatar
    Join Date
    Jan 2010
    Location
    Kansas
    Posts
    522
    Answers
    32
    Vote Rating
    88
      0  

    Default

    Quote Originally Posted by shaleth View Post
    Brilliant - thank you so much! Setting it to false did the trick.
    Cool, glad it was helpful!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •