1, EXT的form表單ajax提交(預設提交方式)
1. function login(item) {
2.
3. if (validatorForm()) {
4. // 登入時將登入按鈕設為disabled,防止重複提交
5. this.disabled = true;
6.
7. // 第一個引數可以為submit和load
8. formPanl.form.doAction('submit', {
9.
10. url : 'user.do?method=login',
11.
12. method : 'post',
13.
14. // 如果有表單以外的其它引數,可以加在這裡。我這裡暫時為空,也可以將下面這句省略
15. params : '',
16.
17. // 第一個引數是傳入該表單,第二個是Ext.form.Action物件用來取得伺服器端傳過來的json資料
18. success : function(form, action) {
19.
20. Ext.Msg.alert('操作', action.result.data);
21. this.disabled = false;
22.
23. },
24. failure : function(form, action) {
25.
26. Ext.Msg.alert('警告', '使用者名稱或密碼錯誤!');
27. // 登入失敗,將提交按鈕重新設為可操作
28. this.disabled = false;
29.
30. }
31. });
32. this.disabled = false;
33. }
34. }
2.
3. if (validatorForm()) {
4. // 登入時將登入按鈕設為disabled,防止重複提交
5. this.disabled = true;
6.
7. // 第一個引數可以為submit和load
8. formPanl.form.doAction('submit', {
9.
10. url : 'user.do?method=login',
11.
12. method : 'post',
13.
14. // 如果有表單以外的其它引數,可以加在這裡。我這裡暫時為空,也可以將下面這句省略
15. params : '',
16.
17. // 第一個引數是傳入該表單,第二個是Ext.form.Action物件用來取得伺服器端傳過來的json資料
18. success : function(form, action) {
19.
20. Ext.Msg.alert('操作', action.result.data);
21. this.disabled = false;
22.
23. },
24. failure : function(form, action) {
25.
26. Ext.Msg.alert('警告', '使用者名稱或密碼錯誤!');
27. // 登入失敗,將提交按鈕重新設為可操作
28. this.disabled = false;
29.
30. }
31. });
32. this.disabled = false;
33. }
34. }
2.EXT表單的非ajax提交
1. //實現非AJAX提交表單一定要加下面的兩行! onSubmit : Ext.emptyFn, submit : function() {
2. //再次設定action的地址
3. this.getEl().dom.action ='user.do?method=login'; this.getEl().dom.method = 'post';
4. //提交submit
5. this.getEl().dom.submit();
6. },
2. //再次設定action的地址
3. this.getEl().dom.action ='user.do?method=login'; this.getEl().dom.method = 'post';
4. //提交submit
5. this.getEl().dom.submit();
6. },
3.EXT的ajax提交
1.
2.
3. Ext.Ajax.request({
4. //請求地址
5. url: 'login.do',
6. //提交引數組
7. params: {
8. LoginName:Ext.get('LoginName').dom.value,
9. LoginPassword:Ext.get('LoginPassword').dom.value
10. },
11. //成功時回撥
12. success: function(response, options) {
13. //獲取響應的json字串
14. var responseArray = Ext.util.JSON.decode(response.responseText);
15. if(responseArray.success==true){
16. Ext.Msg.alert('恭喜','您已成功登入!');
17. }
18. else{
19. Ext.Msg.alert('失敗','登入失敗,請重新登入');
20. }
21. }
22. });
2.
3. Ext.Ajax.request({
4. //請求地址
5. url: 'login.do',
6. //提交引數組
7. params: {
8. LoginName:Ext.get('LoginName').dom.value,
9. LoginPassword:Ext.get('LoginPassword').dom.value
10. },
11. //成功時回撥
12. success: function(response, options) {
13. //獲取響應的json字串
14. var responseArray = Ext.util.JSON.decode(response.responseText);
15. if(responseArray.success==true){
16. Ext.Msg.alert('恭喜','您已成功登入!');
17. }
18. else{
19. Ext.Msg.alert('失敗','登入失敗,請重新登入');
20. }
21. }
22. });