jquery Easyui DataGrid requests two or more times for problem resolution

Source: Internet
Author: User
var $grid = $ ("#elementYEAR_datagrid");
$grid. DataGrid ({
Nowrap:false,//row display data, improve load performance true
Striped:true,//Interlaced color change
Whether the collapsible:false,//can be folded
Fit:true,//height 100%
Method: ' POST ',
Remotesort:false,//data to sort from server definition
pagesize:25,//the number of records displayed per page, default is 10
PageList: [25,30,50,100],//can set a list of the number of record bars per page
pagination:true,//Pagination Control
rownumbers:false,//line number
Singleselect:true,
Toolbar: ' #elementYEAR_tb ',
Onloaderror:function (data) {
Location.href= "/hwip/401.jsp";
}
});


Problem cause \ Workaround


When I entered the page to initialize the DataGrid, I found that two requests were sent to the background, the method of fetching the data was executed two times, but I did not define the URL property when I initialized the DataGrid, and I certainly did not send the request; The code can send the request only $grid.datagrid ( "Load") this sentence, at most will only send once, but the fact is two times, this is why, is this a bug of Easyui? After debugging and thinking of breakpoints, I found that when the DataGrid is initialized, even if you do not define a URL property, there will be "processing, please wait ..." "Such a loading effect (for a moment), but certainly not sent the request, estimated source code through the settimeout to achieve. The problem is here, that is, in the process of settimeout, the following code defines the URL properties, settimeout found the URL is defined, so a request was sent, then I load one time, and then repeatedly sent a request. Having learned such a principle, I solved this problem by joining SetTimeout:


Window.settimeout (function () {
$.extend ($grid. DataGrid ("Options"), {
URL: "Servicedata/getcountyeardata.do",//define the URL here
Queryparams: {ids:cityid}//defines parameters according to the actual situation
});
$grid. DataGrid ("Load");
},100);//Delay 100 ms execution


Complementary solutions


The HTML code uses class to declare the DataGrid, causing Easyui to parse the DataGrid in the class declaration when parsing the class code, so that the component requests a URL, and then invokes the JS initialization code to request the URL once. This results in a duplicate load, and the workaround is to declare the Easyui component with only one initialization method to avoid duplicate commit requests, that is, to remove the class declaration from the HTML (class= "Easyui-datagrid")

Http://jyhft.com/jedjj.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.