加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Extjs form.submit()提交与Ext.Ajax.request的区别

发布时间:2020-12-15 21:52:26 所属栏目:百科 来源:网络整理
导读:转自:http://weizhilizhiwei.iteye.com/blog/1671431 之前总是封不起Extjs中form.submit()提交与Ext.Ajax.request()的区别,现在仍是分不清,但是知道怎么用不会出错了。 方案1: java action中的代码 Java代码 Stringdatastring= "total:" +rehpage.getC

转自:http://weizhilizhiwei.iteye.com/blog/1671431

之前总是封不起Extjs中form.submit()提交与Ext.Ajax.request()的区别,现在仍是分不清,但是知道怎么用不会出错了。

方案1:

java action中的代码

Java代码
  1. Stringdatastring="total:"+rehpage.getCount()+",root:[";
  2. if(rehpage!=null){
  3. datastring+=buildJsonByPage(rehpage);
  4. }
  5. datastring=datastring+"]";
  6. StringBufferbuff=newStringBuffer("{success:true,mes:{");
  7. buff.append(datastring);
  8. buff.append("}}");
  9. System.out.println("datastringis:"+buff.toString());
  10. request.setAttribute("responseText",buff.toString().replaceAll("rn",
  11. "").replaceAll("n",""));//将拼接好的数据放到request
  12. returnSUCCESS;

对用的Extjs中的代码为:

Ext.Ajax.request({

  • url:"./rehearsal/queryTableData.action",250); line-height:18px"> params:{
  • search_place:rehearsal_place,250); line-height:18px"> search_time:dt
  • .format('Y-m-d'),250); line-height:18px"> search_valuation:null,250); line-height:18px"> search_subject:search_subject
  • },250); line-height:18px"> waitMsg:'正在提交数据',250); line-height:18px"> waitTitle:'提示',250); line-height:18px"> method:"POST",250); line-height:18px"> success:function(response){
  • varrespText=Ext.util.JSON
  • .decode(response.responseText);
  • if(respText.success){
  • szcdc_rehearsal_one_grid
  • .getStore()
  • .loadData(respText.mes);
  • failure:function(response){
  • Ext.Msg.alert('提示',250); line-height:18px"> "操作失败:输入非法字符!!!");
  • });
  • }
  • 方案2:

    java action中的代码是:

    );

  • buff.append("}");
  • 对应的Extjs代码为:

    search_form.submit({

  • baseParams:{
  • search_time:search_time,250); line-height:18px"> search_valuation:search_valuation,250); line-height:18px"> success:function(form,action){
  • //得到数据
  • varresult=Ext.util.JSON
  • .decode(action.response.responseText);//就可以取出来。如果是数组,那么很简单
  • //把数据放到结果里面
  • szcdc_rehearsal_one_grid.getStore()
  • .loadData(result);
  • failure:function(form,"操作失败:输入非法字符!!!");
  • });

  • 将form中的字段转成json格式:form.getForm().getFieldValues();

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读