【原】ExtJS 代码收集

1.Ajax获取JSON数据,创建模板,显示到特定Div

Ext.Ajax.request({                           
       url: '/index/getrss',
       success: function(response,options){                               
            var message=Ext.decode(response.responseText);
            console.log(message)                                   
            var t=new Ext.Template(
            '<p>',
            '<span class="bluefont">',
            '<a href="#">{title}</a>',
            '</span>',
            '<br>{description}<br>',
            '<span class="greyfont">{pubdata}</span>',
            '</p>'
            )
            t.compile();
            for(var i=0; i<message.length;i++){
                t.append('rightcont',message[i]);            //绑定到rightcontDiv
            }                   
            },   
            params:{rssurl:'http://news.marketbright.com/feed/'},
            method:'post'
    });

2.典型的Ajax调用

var uname=Ext.getCmp(‘username').getValue();

var pwd=Ext.getCmp(‘password').getValue();

Ext.Ajax.request({                           
                               url: '/login/validate',
                               success: function(response,options){                               
                                    var message=Ext.decode(response.responseText);                                   
                                    if(message=='bind failed'){
                                        Ext.getCmp('messagefield').setVisible(true);                                       
                                    }                               
                            },   
                            params:{username:uname,password:pwd},
                            method:'post'
                        });

3.获取浏览器的URL中的参数,并进行交互

    var url=location.search;      //获取?以及后面的查询字符串                                     
    var paramstr=Ext.util.Format.substr(url,1,url.length);    //去除问号
    var params=Ext.urlDecode(paramstr);    //转成JSON数组
    Ext.getCmp('login').on('click',function(){
        var newpassword=Ext.getCmp('newpassword').getValue();
        var confirmpassword=Ext.getCmp('confirmpassword').getValue();
        if(newpassword==confirmpassword)
        {
            Ext.Ajax.request({
            url:'/login/reset',
            params:{
                sid:params.sid,    //获取JSON数组中的sid
                newpassword:newpassword,
                repeatnewpassword:newpassword
            },
            success:function(response){
                alert('reset password success');
            },
            method:'post'
        })
        }
        else{
            alert('password not match');
        }
    });

原文地址:https://www.cnblogs.com/sophie_wang/p/1788103.html