Results 1 to 4 of 4

Thread: Grid store sync calls wrong URL

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    20
    Answers
    2

    Default Answered: Grid store sync calls wrong URL

    Hi guys,

    here's my store:
    Code:
            
            var store = Ext.create('Ext.data.Store', {
                autoLoad: true,
                autoSync: false,
                model: 'AdminConsole.model.Property',
                proxy: {
                    type: 'rest',
                    url: 'http://localhost:8111/storefront/rest/platform/property',
                    useDefaultXhrHeader : false,
                    reader: {
                        type: 'json'
                    }
                }
            });
    and here's how I sync it:
    Code:
        onSaveClick: function() {
            var grid = Ext.getCmp('system-properties-grid');
            grid.getStore().sync({
                success: function(batch, options) {
                    store.load();
                    Ext.toast({
                        html: 'Successfully saved!',
                        closable: false,
                        align: 't',
                        slideInDuration: 400,
                        minWidth: 400
                    });
                },
                failure: function(batch, options) {
                    var error = Ext.decode(responseObject.responseText);
                    Ext.Msg.alert('Error', 'Error: ' +  error);
                }
            }); 
        }
    but when I try to sync it - a PUT request it made to this URL:
    Code:
    http://localhost:8111/storefront/rest/platform/property/AdminConsole.model.Property-1?_dc=1403338276238 405 (Request method 'PUT' not supported)
    and with extjs4 it was making a PUT request to
    Code:
    /rest/platform/property

  2. Found it - looks like my model does not have an id property so it constructs the URL as property/{id}. After I add the idProperty: 'key' to my model it all works fine.

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,250
    Answers
    758

    Default

    Please post a runnable test case, there's not enough info. What does the store contain when you're trying to sync it? Also, are you trying to make a cross domain request here? Typically you'll just have a relative url.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    20
    Answers
    2

    Default

    Hi Evant,

    thanks for your reply. I tried to setup a fiddle for you to look at, but unfortunately it requires a REST controller so it was not so easy. However I have a fiddle if you want to look at here:

    https://fiddle.sencha.com/#fiddle/6ud

    My controller (http://localhost:8111/storefront/rest/platform/property) returns a structure like this:

    Code:
    [ {  "key" : "awt.toolkit",  "value" : "sun.awt.X11.XToolkit"}, {  "key" : "file.encoding",  "value" : "UTF-8"}, {  "key" : "org.slf4j.simpleLogger.defaultLogLevel",  "value" : "info"}, {  "key" : "java.net.preferIPv4Stack",  "value" : "true"}]
    and I also attach a screenshot for you. The weirdest thing is that it works when I add a new row and sync, it works when I call store.loadData(data) and then sync. But it doesn't work if I call store.load() to load the data from the server, then edit the cell of the grid and call sync().1.jpg

  5. #4
    Sencha User
    Join Date
    Jan 2013
    Posts
    20
    Answers
    2

    Default

    Found it - looks like my model does not have an id property so it constructs the URL as property/{id}. After I add the idProperty: 'key' to my model it all works fine.

Posting Permissions

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