1, EXT的form表單ajax提交(默認提交方式)

Code

1. function login(item)
{
2.

3. if (validatorForm())
{
4. // 登錄時將登錄按鈕設為disabled,防止重復提交
5. this.disabled = true;
6.
7. // 第一個參數(shù)可以為submit和load

8. formPanl.form.doAction('submit',
{
9.
10. url : 'user.do?method=login',
11.
12. method : 'post',
13.
14. // 如果有表單以外的其它參數(shù),可以加在這里。我這里暫時為空,也可以將下面這句省略
15. params : '',
16.
17. // 第一個參數(shù)是傳入該表單,第二個是Ext.form.Action對象用來取得服務器端傳過來的json數(shù)據(jù)

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提交

Code
1. //實現(xiàn)非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. },

3.EXT的ajax提交

Code
1.
2.

3. Ext.Ajax.request(
{
4. //請求地址
5. url: 'login.do',
6. //提交參數(shù)組

7. params:
{
8. LoginName:Ext.get('LoginName').dom.value,
9. LoginPassword:Ext.get('LoginPassword').dom.value
10. },
11. //成功時回調(diào)

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. });

Tag標簽: ext,表單提交