EXTJS4.0 用法笔记~~ 3种和后台交互数据的方法

真他么不想说,现在iteye发表个文章真难,一些提示信息只能体现此网站的不专业:输入信息有误?能给个具体的提示哪里输入有误行么,正规正举的几个汉字也得罪你了.都是搞IT的,这点也做不好?.吐槽一下.希望有更多的人投诉,让其改进.

1.数据源store

store通常是作为grid的数据源,以便来更新grid的数据.其实这也是它最正规的用法,但其也可以把它作为与后台交互的一种方法,前提是只需向后台发送数据,而不需要接收后台返回的数据.

    创建一个公共的store,不与任何表有联系,只需要下面简单的几句话


    var publicstore = Ext.create('Ext.data.Store', {   
           proxy : {
                type : 'ajax',
                url : ''
           }
      });

 如果只是想往后台传个数据的话

 publicstore.proxy.url='a.action?id=1';

   publicstore.load();




2.form表单的提交方法

  表单提交涉及到两种,第一就是单纯的提交表单,把该表单的信息提交到后台action处理,不用任何参数

                       fs.form.submit( {
                                        clientValidation : true,
                                         url : 'saveform.action',
                                         method : 'POST',
                                         success : function(form, action) {                                          
                                         },
                                         failure : function(form, action) {
                                         }
                                     });





第二,就是作为后台交互,传输数据,需加上要传输的参数


                                    fs.form.submit( {
                                        clientValidation : true,
                                         url : 'delbyid.action?id=' + encodeURI(id),
                                         method : 'POST',
                                         success : function(form, action) {                                          
                                         },
                                         failure : function(form, action) {
                                         }
                                     });




3.用Ext.Ajax.request

      这个最简单,最方便,增删改操作都可以用,而且不用估计啥,唯一需要注意的就是网页和项目的编码格式


                                           Ext.Ajax.request( {
                                                         timeout : 3000000,
                                                         url : 'save.action',
                                                         params : 'id='+ encodeURI(id)+ '&descr='+ encodeURI(descr) ,
                                                         success : function(response, config) {                                                    
                                                         },
                                                         failure : function(form, action) {
                                                            
                                                         }
                                                     })

你可能感兴趣的:(Extjs4.0)