1. #1
    Sencha Premium Member
    Join Date
    Apr 2013
    Posts
    16
    Answers
    1
    Vote Rating
    1
    shaleth is on a distinguished road

      0  

    Default Answered: Restful post missing brackets on single record

    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
    31
    Vote Rating
    85
    existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice

      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
    shaleth is on a distinguished road

      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
    31
    Vote Rating
    85
    existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice

      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!

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi