1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    13
    Vote Rating
    0
    csoon1 is on a distinguished road

      0  

    Default Need help passing result of Ajax GET to an item in a panel

    Need help passing result of Ajax GET to an item in a panel


    I need to pass the response of an Ajax request to an Accordion item. my code (just simplified) looks like:

    Code:
    Ext.Ajax.request({
      method: 'GET',
      url:'test.cgi',
      success: function(response) {
        // Need to pass response.responseText to the html on the item below
      }
    });
    
    var testitem1 = new Ext.Panel({
      title: 'Test Item 1',
      html: // I wanted to pass the above response.responseText here
    });
    I thought declaring a variable globally... then modifying its value locally will permanently modify the variable's value... making such value accessible even on other functions. My code below didn't work:

    Code:
    var lazy = ''; // the global variable
    Ext.Ajax.request({
      method: 'GET',
      url:'test.cgi',
      success: function(response) {
        lazy = response.responseText;
      }
    });
    
    var testitem1 = new Ext.Panel({
      title: 'Test Item 1',
      html: lazy
    });
    Please let me know a professional way of doing this. Thanks!

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Location
    West Linton, Scotland
    Posts
    244
    Vote Rating
    0
    andycramb is on a distinguished road

      0  

    Default


    Have you had a look at the autoLoad config option of the Panel class.
    If you don't want to update on render you could retrieve the updater using the getUpdater method and use the returned updater object.

  3. #3
    Ext User
    Join Date
    Aug 2009
    Posts
    13
    Vote Rating
    0
    csoon1 is on a distinguished road

      0  

    Default


    Quote Originally Posted by andycramb View Post
    Have you had a look at the autoLoad config option of the Panel class.
    If you don't want to update on render you could retrieve the updater using the getUpdater method and use the returned updater object.

    Okay I got to update the html in my panel through autoLoad... however I have some more questions if you don't mind. Below is the updated code:

    Note: I removed the Ajax request in the original post and used....

    Code:
    var testitem1 = new Ext.Panel({
      title: 'Test Item 1',
      autoLoad: {
        url: 'test.cgi',
        method: 'GET',
        params: 'test'    // Not  intended but this would be my first question
      }
    });
    My test.cgi script only has this simple code:

    Code:
    print qq|Content-type: text/xml\n\n
    <news><headline>$head</headline><msg>$msg</msg></news>|;
    Now when I load the my page... a request is made to the .cgi script and the response is received... and the content of my Panel is updated to show the returned xml content. However....

    1) How come the page is blank if I remove params: 'test' from autoLoad? I am only trying to 'GET' something from the server so I don't need params.

    2) Is there a way I can play with the response received? I tried this on the autoLoad:

    Code:
    callback: function(response) {
      alert(response.responseText);
    }
    but the alert box shows "undefined". I am expecting to see the responseText. The reason why I want to play with the response is somehow I wanted to update the title of my Panel.

    Overall, this is what I wanted to achieve with my end application:
    a. The item is for an Accordion layout. The item in the accordion would show some news items... that's why I'm trying to pull the data (which is the news body)... and autoloading it on the item.
    b. I wanted the news headline to be the title of the item.

    Thanks for your help.

  4. #4
    Ext User
    Join Date
    Aug 2009
    Posts
    13
    Vote Rating
    0
    csoon1 is on a distinguished road

      0  

    Default


    bump

  5. #5
    Sencha - Community Support Team mschwartz's Avatar
    Join Date
    Nov 2008
    Location
    San Diego, Peoples' Republic of California
    Posts
    2,053
    Vote Rating
    17
    mschwartz will become famous soon enough mschwartz will become famous soon enough

      0  

    Default


    Code:
    var testPanel = new Ext.Panel({
      id: 'test-panel',
      title: 'test panel'
    });
    
    // after the panel is rendered:
    Ext.Ajax.request({
      method: 'POST',  // I always post
      url: 'whatever.pl', // looks like you use perl
      params: { ... }, // whatever you want to pass
      success: function(response) {
        Ext.getCmp('test-panel').body.update(response.responseText);
      }
    });

  6. #6
    Ext User
    Join Date
    Aug 2009
    Posts
    13
    Vote Rating
    0
    csoon1 is on a distinguished road

      0  

    Default


    thanks. it's just what i wanted.

  7. #7
    Sencha User
    Join Date
    Apr 2008
    Location
    West Linton, Scotland
    Posts
    244
    Vote Rating
    0
    andycramb is on a distinguished road

      0  

    Default another option

    another option


    This post points to another solution which could be an option as well. The solution is below and uses the panels render event to the get the updater object and custom render the response.

    Code:
    listeners:{
    	render:{
    		fn:function(){
    			this.getUpdater().setRenderer({
    				render:function(targetEl,response){
    					reviewTemplate.overwrite(targetEl,Ext.decode(response.responseText).data);
    				}
    			})
    		},
    		single:true
    	}
    }

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar