Easyui动态加载后台数据的例子

前端之家收集整理的这篇文章主要介绍了Easyui动态加载后台数据的例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

JS:

/**接口验证查询按钮*/
function strategyCheckSearch(){
	var strategyRows= $("#strategyCheckDg").datagrid('getRows');
	var strategyIp = $("#strategyIp").val().trim();
	var strategyPort = $("#strategyPort").val().trim();
	if(strategyIp.length < 1 || strategyPort.length < 1){
		$.messager.alert("错误","请输入IP和端口!",'info');
	}else{
		$.each(strategyRows,function(i,row){
			$.ajax({
				url : 'require/getStatusCodeByWget',type : 'post',data : {
					wgetString : JSON.stringify(row.wget),strategyIp : strategyIp,strategyPort : strategyPort
				},success : function(data) {
					var str = "";
					$.each(data,result){
						console.log(result);
						if(result.proxyPort == null){//端口值为null则不显示
							str += "【"+result.proxyAddress+"】"+result.responses[0].Failed+"<br>";
						}else{
							str += "【"+result.proxyAddress+":"+result.proxyPort+"】"+result.responses[0].Failed+"<br>";
						}
					});
					$("#strategyCheckDg").datagrid('updateRow',{
						index:i,row:{
							status : str
						}
					});
				}
			});
			
		});
	}
	
}

Controller:

/**根据wget获取状态码*/
@RequestMapping("getStatusCodeByWget")
@ResponseBody
public List<WgetResult> getStatusCodeByWget(@RequestParam("wgetString") String wgetString,HttpServletRequest request,@RequestParam("strategyIp") String strategyIp,@RequestParam("strategyPort") String strategyPort) {
	Wget wget = GsonUtil.toObject(wgetString,Wget.class);
	String[] ipStrings = strategyIp.split(",");
	List<String> ipList = Arrays.asList(ipStrings);
	List<WgetResult> WgetResultList = domainTransferService.validityStrtegy(wget,ipList,strategyPort);
	return WgetResultList;
}  
要点就是使用$.ajax从后台获取数据之后,在success方法获取easyui所有行的数据,然后通过$("#").datagrid('updateRow',{});刷新前台数据就可以实现了. 原文链接:https://www.f2er.com/ajax/162806.html

猜你在找的Ajax相关文章