extJs學習基礎3 ajax與php互動

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   使用   sp   for   

extJs代碼:

  1 <script src="build/ext-all.js"></script>  2     <script src="build/packages/ext-theme-crisp/build/ext-theme-crisp.js"></script>  3     <link rel="stylesheet" href="build/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css">  4   5 <script>  6         Ext.onReady(function(){  7             // 登入介面  8             Ext.define(‘Login‘,  {    9                 requires:[‘LoginController‘],     // 要使用載入的類 10                 extend: ‘Ext.window.Window‘,   11                 controller: ‘login‘,   12                 closable: false,   13                 resizable : false,   14                 modal: true,   15                 //draggable: false,   16                 autoShow: true,   17                 title: ‘使用者登入---OA辦公系統‘,   18                 items:[{   19                     xtype:‘form‘,//父表單   20                     reference: ‘form‘,   21                     bodyPadding: 20,   22                     items:[{   23                         xtype: ‘textfield‘,   24                         name: ‘username‘,   25                         labelWidth: 50,   26                         fieldLabel: ‘使用者名稱‘,   27                         allowBlank: false,   28                         emptyText: ‘使用者名稱或郵箱地址‘   29                       },{   30                         xtype: ‘textfield‘,   31                         name: ‘password‘,   32                         labelWidth: 50,   33                         inputType: ‘password‘,    34                         fieldLabel: ‘密  碼‘,   35                         allowBlank: false,   36                         emptyText: ‘請輸入您的密碼‘   37                       }]   38                 }],   39                 buttons: [{   40                             name: ‘registbutton‘,   41                             text: ‘使用者註冊‘,    42                           },{   43                             name: ‘loginbutton‘,   44                             text: ‘使用者登入‘,    45                             region: ‘center‘,   46                             listeners:{   47                               click: ‘onLoginbtnClick‘//單擊事件 調用 LoginController 中的onLoginbtnClick函數   48                             }   49                           }]   50               }   51             );  52  53             // 登入按鈕的響應 54  55             Ext.define(‘LoginController‘, {   56                 extend: ‘Ext.app.ViewController‘,   57                 alias: ‘controller.login‘,   58                //使用者登入按鈕事件處理   59                onLoginbtnClick: function(){   60                     //根據 view form中設定的 reference:form 中返回一個組件 61                     var form = this.lookupReference(‘form‘);  62                     // 判斷是否是有效欄位 (這個不是很明白) 63                     if (form.isValid()) {  64                         this.login({   65                             data: form.getValues(),   66                             scope: this,   67                             success: ‘onLoginSuccess‘,   68                             failure: ‘onLoginFailure‘   69                     })}  70                 },   71                 login: function(options) {  72                     // 調用ajax 73                     Ext.Ajax.request({   74                         url: ‘test.php‘,   75                         method: ‘POST‘,   76                         params: options.data,   77                         scope: this,   78                         //callback: this.onLoginReturn, //回呼函數  79                         success: this.onLoginSuccess,   //ajax請求成功 80                         failure: this.onLoginFailure,   //ajax請求失敗 81                         original: options   82                     });   83                 },   84                  85                 onLoginSuccess: function(response, options){ 86                     var result = response.responseText; 87                     //將json字串轉成 json 88                     var resultJson = JSON.parse(result); 89                      90                     if(resultJson.flag){ 91                         alert(‘success‘); 92                     }else{ 93                         alert(‘failure‘); 94                     } 95                 }, 96  97                 onLoginFailure: function(response, options){ 98                     alert(‘ajax請求失敗‘); 99                 }100               }  101             );  102 103             var log = new Login();104             log.show();105 106         });107     </script>

php代碼

 1 <?php  2     if(isset($_POST)){ 3         if($_POST[‘username‘] == ‘123‘){ 4             $result = array(‘flag‘=>true); 5             echo json_encode($result); 6         }else{ 7             $result = array(‘flag‘=>false); 8             echo json_encode($result); 9         }10     }11 ?>

 

extJs學習基礎3 ajax與php互動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.