Results 1 to 10 of 18

Thread: Add parameters to Ajax proxy

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Aug 2010
    Location
    Europa
    Posts
    216
    Vote Rating
    1
      0  

    Question Add parameters to Ajax proxy

    How do you add parameters to an Ajax store?

    I am bypassing the cross domain policy by using a php proxy on my server. I am trying to send a few needed parameters to the php page and I expect the response to be xml.

    But how do I send certain parameters to the php page on the server?

    PHP Code:
      var orderStore = new Ext.data.Store({
                
    model'order',
                
    urlvarxml,
                
    proxy: {
                    
    type:'ajax',
                    
    id'data',
                    
    url'proxytest.php',
                    
    method"POST",
                    
    params:{action'askorderlist',
                         
    question'uborderlist',
                         
    value'2010-08-01',
                         
    user'username',
                         
    password'password'
                     
    },
                    
    reader: {
                        
    type'xml',
                        
    record'order'
                    
    }
                },
        
    autoloadtrue,
        }); 

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    311
    Vote Rating
    5
      1  

    Default

    Just append the parameter to the url:

    Code:
    var orderStore = new Ext.data.Store({
                model: 'order',
                url: varxml,
                proxy: {
                    type:'ajax',
                    id: 'data',
                    url: 'proxytest.php?username=dummy&age=' + somevar,
                    method: "POST",
                    params:{action: 'askorderlist',
                         question: 'uborderlist',
                         value: '2010-08-01',
                         user: 'username',
                         password: 'password'
                     },
                    reader: {
                        type: 'xml',
                        record: 'order'
                    }
                },
        autoload: true,
        });

  3. #3
    Sencha User
    Join Date
    Aug 2010
    Location
    Europa
    Posts
    216
    Vote Rating
    1
      1  

    Default

    Isn't that a 'GET'? And if so, isn't there a limit to the number of characters you can append to the url?

    What if I want to use a 'POST'?

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,583
    Vote Rating
    873
      1  

    Default

    Code:
    Ext.setup({
        onReady: function(){
            Ext.regModel('Foo', {
                fields: ['a']    
            });
            
            new Ext.data.Store({
                autoLoad: true,
                model: 'Foo',
                proxy: {
                    url: 'data.asp',
                    type: 'ajax',
                    extraParams: {
                        foo: 'bar'
                    }
                }
            });
        }
    });
    By default all read operations will be a get. You can override it for a single instance by using:

    Code:
    // create store
    myStore.proxy.actionMethods.read = 'POST';
    myStore.load();
    Or globally:
    Code:
    Ext.apply(Ext.data.AjaxProxy.prototype.actionMethods, {
         read: 'POST'
    });
    // create store
    Evan Trimboli
    Twitter - @evantrimboli

  5. #5
    Sencha User
    Join Date
    Aug 2010
    Location
    Europa
    Posts
    216
    Vote Rating
    1
      0  

    Default

    Thanks Evant for your quick response. In your example the extraParams you pass to the proxy also are present in the model, is this a necessity?

    I am still getting errors. Is there a 'success' and 'failure' parameter for stores or readers, like with an Ext.Ajax.request?
    PHP Code:
    XHR finished loading"http://localhost/proxytest.php?_dc=1285569086510".ext-touch-debug.js:7732
    Uncaught 
    #<an Object>
    getResponseData ext-touch-debug.js:7732
    readext
    -touch-debug.js:7235
    (anonymous function)ext-touch-debug.js:6620
    onCompleteext
    -touch-debug.js:14577
    onStateChangeext
    -touch-debug.js:14524
    (anonymous function)ext-touch-debug.js:2618 

  6. #6
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,583
    Vote Rating
    873
      0  

    Default

    No, I just happened to use the same name for the model and the property, they are in no way related.

    As for the other one, it sounds like you're sending back malformed data.
    Evan Trimboli
    Twitter - @evantrimboli

Similar Threads

  1. Ajax.request VS Store proxy
    By merry andrew in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 23 Aug 2010, 4:09 PM
  2. Ajax Proxy/Json Store
    By eldiego34 in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 19 Aug 2010, 4:59 AM
  3. Replies: 2
    Last Post: 29 Jun 2010, 2:46 PM
  4. Problem with proxy ajax call
    By mysticav in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 4 Dec 2008, 12:10 PM
  5. is data proxy is the same as ajax?
    By ratno in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 24 Nov 2008, 8:35 AM

Posting Permissions

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