1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    6
    Vote Rating
    0
    rolfiee is on a distinguished road

      0  

    Default Answered: my refresh twitter function is not working

    Answered: my refresh twitter function is not working


    Hi there,

    This is the first application that i try. I have made a refresh function in it. But it won't work.
    It seems that the function gridRefresh does not update the resultPanel with new data.

    Code:
    Ext.setup({
        onReady: function() {
            var topToolbar = new Ext.Toolbar({
                dock : 'top',
                ui: 'dark',
                title: 'Sencha Twitter Search'
            });
    
    
             var tpl = new Ext.XTemplate(
                '<div id="tweet_container">',
                    '<tpl for=".">',
                        '<div class="tweet_data">',
                        '<div class="tweet_avatar">',
                            '<img width="30" height="30" src="{profile_image_url}"/>',
                        '</div>',
                        '<div class="tweet_content">',
                            '<a class="user" href="http://twitter.com/{from_user}">{from_user}</a>&nbsp;',
                            '{text}',
                        '</div>',
                        '<div class="clear"></div>',
                        '</div>',
                    '</tpl>',
                '</div>'
             );
    
    
        var resultPanel = new Ext.Panel({
                layout: 'fit',
                style: 'padding-bottom: 10px;',
                tpl: tpl
            });
    
    
        var searchPanel = new Ext.Panel({
                padding: 10,
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                },
                items: [{
                    flex: 4,
                    xtype: 'textfield',
                    style: 'margin-right: 10px;',
                    id: 'textquery'
                },{
                       flex: 2,
                    xtype: 'button',
                    text: 'Search',
                       handler: function() {
                        var query = Ext.getCmp("textquery").getValue();
                        Ext.Ajax.request({
                            url: 'search.php?act=search&q='+query,
                               success: function(e) {
                                var obj = Ext.util.JSON.decode(e.responseText);
                                var msg = obj.results;
                                var html = tpl.apply(msg);
                                resultPanel.update(html);
                            }
                        });
                    }
                }]
            });
    
    
    
    var t = setInterval('gridRefresh()',10000);
    function gridRefresh(){
                        Ext.Ajax.request({
                            url: 'search.php?act=search&q=earth',
                            success: function(e) {
                                var obj = Ext.util.JSON.decode(e.responseText);
                                var msg = obj.results;
                                var html = tpl.apply(msg);
                                resultPanel.update(html);
                            }
                            });
                            }
    
    
           var myPanel = new Ext.Panel({
                dockedItems: [topToolbar],
                items: [searchPanel, resultPanel],
            scroll: 'vertical',
                style: 'background: #DDEEF6;',
                fullscreen : true
            });
    
    
        }
    
    
    });
    Can anybody help me out.

    Thanks!

  2. Ahh, I see the problem. The setInterval can't find your gridRefresh function because your gridRefresh function isn't defined globally. But that's ok, just move your setInterval to after your gridRefresh function and don't surround the function name in parens.

    Code:
            //var t = setInterval('gridRefresh()',10000); // << remove this
            function gridRefresh(){
                Ext.Ajax.request({
                    url: 'jrr-search-twitter.php?act=search&q=earth',
                    success: function(e) {
                        var obj = Ext.util.JSON.decode(e.responseText);
                        var msg = obj.results;
                        var html = tpl.apply(msg);
                        resultPanel.update(html);
                    }
                });
            }
            var t = setInterval(gridRefresh,10000);  // << and add this

  3. #2
    Sencha - Services Team
    Join Date
    Mar 2007
    Location
    Foristell, MO
    Posts
    1,108
    Answers
    12
    Vote Rating
    3
    jratcliff is on a distinguished road

      0  

    Default


    have you put in any breakpoints to confirm that the success callback is called? If it is being called, what does the data look like?
    Jack Ratcliff
    Sencha Inc, Green bleeding Senchan

    How to report a bug:
    http://www.sencha.com/forum/showthre...o-report-a-bug

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    6
    Vote Rating
    0
    rolfiee is on a distinguished road

      0  

    Default


    Thanks for you reply. Here is the search.php code:

    Code:
    <?phpif (isset($_GET["act"]) && $_GET["act"] == "search") {
        $url = 'http://search.twitter.com/search.json?q='.$_GET["q"];
    
    
        $content = file_get_contents($url);
        $array = json_decode($content);
    
    
        $data = array();
    
    
        foreach ($array->results as $var => $value)
        {
         	// adding url
            $pattern = '/\b(https?:\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i';
            preg_match_all($pattern, $value->text, $regs);
            $loop = count($regs[0]);
    
    
            for ($i = 0; $i < $loop; $i++) {
                $value->text = str_replace($regs[0][$i], '<a class="outlink" href="'.$regs[0][$i].'">'.$regs[0][$i].'</a>', $value->text);
            }
    
    
    	$data[] = array(
                "profile_image_url" => $value->profile_image_url,
                "from_user"         => $value->from_user,
                "text"              => $value->text
            );
        }
    
    
        $out = array(
            "success" => true,
            "results" => $data
        );
    
    
        echo json_encode($out);
        exit;
    }
    ?>
    The success callback is working ok, It is the same code when you search with the searchPanel.

  5. #4
    Sencha - Services Team
    Join Date
    Mar 2007
    Location
    Foristell, MO
    Posts
    1,108
    Answers
    12
    Vote Rating
    3
    jratcliff is on a distinguished road

      0  

    Default


    Ahh, I see the problem. The setInterval can't find your gridRefresh function because your gridRefresh function isn't defined globally. But that's ok, just move your setInterval to after your gridRefresh function and don't surround the function name in parens.

    Code:
            //var t = setInterval('gridRefresh()',10000); // << remove this
            function gridRefresh(){
                Ext.Ajax.request({
                    url: 'jrr-search-twitter.php?act=search&q=earth',
                    success: function(e) {
                        var obj = Ext.util.JSON.decode(e.responseText);
                        var msg = obj.results;
                        var html = tpl.apply(msg);
                        resultPanel.update(html);
                    }
                });
            }
            var t = setInterval(gridRefresh,10000);  // << and add this
    Jack Ratcliff
    Sencha Inc, Green bleeding Senchan

    How to report a bug:
    http://www.sencha.com/forum/showthre...o-report-a-bug

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    6
    Vote Rating
    0
    rolfiee is on a distinguished road

      0  

    Default


    Thanks, I miss that! You solve my problem. Kudos for you!

Thread Participants: 1