当前位置: 代码迷 >> JavaScript >> Extjs form.submit()交付与Ext.Ajax.request的区别
  详细解决方案

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

热度:127   发布时间:2012-11-23 00:03:43.0
Extjs form.submit()提交与Ext.Ajax.request的区别

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

方案1:

java action中的代码

		String datastring = "total : " + rehpage.getCount() + ", root : [";
		if (rehpage != null) {
			datastring += buildJsonByPage(rehpage);
		}
		datastring = datastring + "]";
		StringBuffer buff = new StringBuffer("{success:true,mes:{");
		buff.append(datastring);
		buff.append("}}");

		System.out.println("datastring is: " + buff.toString());
		request.setAttribute("responseText", buff.toString().replaceAll("\r\n",
				" ").replaceAll("\n", " "));// 将拼接好的数据放到request
		return SUCCESS;

?对用的Extjs中的代码为:

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

?方案2:

java action中的代码是:

?

		String datastring = "total : " + rehpage.getCount() + ", root : [";
		if (rehpage != null) {
			datastring += buildJsonByPage(rehpage);
		}
		datastring = datastring + "]";
		StringBuffer buff = new StringBuffer("{success:true,");
		buff.append(datastring);
		buff.append("}");

		System.out.println("datastring is: " + buff.toString());
		request.setAttribute("responseText", buff.toString().replaceAll("\r\n",
				" ").replaceAll("\n", " "));// 将拼接好的数据放到request
		return SUCCESS;

?对应的Extjs代码为:

							search_form.submit({
								url : "./rehearsal/queryTableData.action",
								baseParams : {
									search_place : rehearsal_place,
									search_time : search_time,
									search_valuation : search_valuation,
									search_subject : search_subject
								},
								waitMsg : '正在提交数据',
								waitTitle : '提示',
								method : "POST",
								success : function(form, action) {
									// 得到数据
									var result = Ext.util.JSON
											.decode(action.response.responseText);// 就可以取出来。如果是数组,那么很简单
									// 把数据放到结果里面
									szcdc_rehearsal_one_grid.getStore()
											.loadData(result);
								},
								failure : function(form, action) {
									Ext.Msg.alert('提示', "操作失败:输入非法字符!!!");
								}
							});
?
  相关解决方案