jquery DataTables, first load no problem, reload DataTables popup error: Cannot reinitialise DataTable

Source: Internet
Author: User

jquery DataTables, first load no problem, reload DataTables popup error: Cannot reinitialise DataTable.

How to solve.

1 Solutions on-line:






2 of my attempts.

1) Try 1.

Add Retrieve:true and destroy:true two parameters can see also: retrieveoption destroyoption parameter specific meaning

http://datatables.club/faqs/



Plus, although there is no error, or there is a problem, is that Ajax is only executed once, click on Ajax again does not trigger, that is, the background action is only performed once. This is certainly not going to work.

2) Try 2

Just add, $n. DataTable (). Fndestroy (); (Note that a DataTable, not a DataTable, note the case, or it is not an invalid method.) The DataTable is the use of jquery, the DataTable is the use of Amazeui)

Can only trigger Ajax two times, the third time the error.


I go to the Internet, it may be related to Google Browser, I will Google browser for IE browser, will not error.

3) Try 3

Plus retrieve:true and destroy:true two parameters, plus $n.datatable (). Fndestroy ();

Can only trigger Ajax two times, the third time the error. Google Browser There is this problem, ie browser, will not error.


5) Try 5

Add "Retrieve" property

Then add $n.datatable (). Fnreloadajax ();.

The perfect solution, no matter how many clicks, will normally call Ajax to the background load.


Http://bbs.csdn.net/topics/391955498?page=1

But if only add $n.datatable (). Fnreloadajax (); , does not add retrieve attribute, although can also load Ajax to the background every time, but will error:


However, the test found that the "retrieve" attribute was added and then increased by $n.datatable (). Fnreloadajax ();. There is still a problem with this approach.

Although Ajax is reloaded every time, Ajax executes the URL that is written when the URL is the first click, including the one behind. NAME=XX&TYPE=XX), so there will be a problem. If I was doing statistics, each time I clicked "Query", I might have modified the query condition so that the URL would be re-prefixed to the value of the parameter to form a new Ur.

namely Url= url+ "? Name=" + $ ("#name"). Val () + "&type=" + $ ("#type"). Val ()

But in this way, the new URL is not executed (the parameter value behind the URL is not changed, and the background plus breakpoint is easy to find).

What to do.

To reset the value of the AJAX member variable of the DataTable , let him execute the latest URL, because the parameters after each load URL may be different (for example, when making a query, you may want to modify the query criteria, the value of the query condition is prefixed to the URL?).

Here's how:

http://blog.csdn.net/nihaoqiulinhe/article/details/53421230


My implementation code:

var datatablessettings = $n. DataTable (). Fnsettings ();
Datatablessettings.ajax = {
"url": href,
"Pipe": true,
"Data": {//Because the parameter is prefixed to the href, so data is actually useless to me.
"XX": XX,
"XX": XX
}
};//re-setting the URL

=====

Summarize:

0 to implement multiple loading, will normally perform Ajax to the background, to three things.

①retrieve Property

②fnsettings, reset URL

③fnreloadajax, re-execute Ajax



The function of the 1retrieve property is simply that it is used to control the error box without popping up the following.


2jQuery DataTables, executes $ ("#xxx"). DataTable ({...} ), the default is to load only once, that is, to perform Ajax only once to the background.


3 to repeat the load, that is, click once, call Ajax to the background, it is necessary to call the $ ("#xxx"). DataTable (). Fnreloadajax (); But it's not enough to do this, but to reset the dataTable's Ajax, let him execute the latest URL , because the parameters after each load URL may be different (for example, when you do a combination query, you may want to modify the query criteria, the value of the query condition is prefixed to the URL?).




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.