JQuery EasyUI load twice url reason analysis and solution

  • 2020-03-30 03:42:18
  • OfStack

1. The traditional way


<span style="font-size:18px;">$(function () { 
var url = "../Source/Query/jhDataQry.ashx?action=query"; 
$(dg).datagrid({ 
url: url, 
queryParams: { 
qsrq: qsrq, 
zzrq: zzrq 
} 
}); 
}) 

<table id="DataGrid" class="easyui-datagrid" fit="true" border="false" toolbar="#TBar" pagination="true" 
data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh', queryParams: { 'action': 'query'}" 
rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx"> 
<thead> 
<tr> 
</tr> 
</thead> 
</table></span>

2. Cause analysis and solution

The HTML code declares the datagrid with class, causing easyUI to parse the class code by parsing the datagrid in the class declaration, so that the component requests the url once; The js initialization code is then called again to request the url. This results in duplicate loads. The solution is to declare the easyUI component with only one initialization method to avoid duplicate commit requests, which is to delete the class declaration in the HTML (class="easyui-datagrid"). The modified code is as follows:


<span style="font-size:18px;"><table id="DataGrid" fit="true" border="false" toolbar="#TBar" pagination="true" 
data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh'" 
rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx"> 
<thead> 
<tr> 
</tr> 
</thead> 
</table></span>


Related articles: