Duplicate submission of form in Easyui tab-loaded page

Source: Internet
Author: User

http://blog.csdn.net/fxz1982/article/details/8987769

The tabs component in Easyui loads the target page in an href manner, if a form is placed in a Easyui component such as dialog or window in the target page. Then turn this tab off again. If you do a form submission, you will receive two submission requests in the background. Repeating the above operation again will receive 3 commit requests, if the form serialize () after the post submission server of jquery will receive the values are all organized in an array way.

After analysis, Easyui's tab loading page will take the DOM code of the target page's dialog component from the target page and put it into the DOM structure of this page. Look at the following differences in the target page before and after dialog initialization

1. The original DOM structure of the target page is as follows (the dialog in the page is not instantiated)

where <!--form--and code <div id= "Dept-dialog" ...> is the dialog that contains the form

2. If the target page instantiates dialog at load time, the code is as follows

You can see that the DOM structure of the < <div id= "Dept-dialog" ...> code is changed and moved to the lower-middle position.

3. Then take a look at what happened after this page was tabs loaded

, in the blue box is the target DOM loaded in the tab, you can see the red box <!--<div id= "Dept-dialog" ...> code is removed from the DOM structure of the target page. is moved to the DOM structure of the page on which the tabs component is located, because the DOM is too large to be truncated when it is expanded.

This is the problem, when the target page in tabs is closed, Easyui destroys the DOM content in the blue box, but the dialog component in the target page is moved outside, causing the DOM content of the dialog not to be destroyed with the target page, and when the target page is loaded again in tab mode, The same block of <div id= "Dept-dialog" ...> code content is generated in the DOM structure of the page where the tab component is located. This results in a duplicate submission of the form.

Workaround: There is no good way, stupid, in front of the tabs loading page, the ID of all the components in the tab page is recorded, and the object is manually found when the tab is closed.

Code at load time:

[JavaScript]View Plaincopy
  1. $ (' #my-tabs '). Tabs (' Add ', {
  2. Title:title,
  3. Href:url,//address of the content page
  4. Border: false,
  5. Closable:True,
  6. Id:title,
  7. Extractor: function (data) {
  8. //Extract the contents of the body
  9. var pattern =/<body[^>]*> (. | [\n\r])  *) <\/body>/im;
  10. var matches = pattern.exec (data);
  11. if (matches) {
  12. data = matches[1];
  13. }
  14. var tmp = $ (' <div/> '). HTML (data);
  15. var divs = $ (TMP). Find (' [id] ');
  16. var ids = [];
  17. For (var i=0;i<divs.length;i++) {
  18. Ids.push (Divs[i].getattribute ("id"));
  19. }
  20. //log all div with ID in tab
  21. $ (' #base-tabs '). Tabs ('gettab ', title). DIVs = IDs;
  22. return data;
  23. }


Action when closed:

[JavaScript]View Plaincopy
    1. $ (' #my-tabs '). Tabs ({
    2. Autowidth:True,
    3. Onbeforeclose: Function(title,index) {//close the panel before releasing the resource for this feature
    4. var tab = $ (this). Tabs (' Gettab ', index);
    5. //Prepare to delete div content
    6. $ (' #my-tabs '). attr ("Rmdiv", Tab.divs);
    7. },onclose: function () {//delete the DOM object used in tab closing
    8. var divs = $ (' #my-tabs '). attr ("rmdiv"). Split (",");
    9. For (var i=0;i<divs.length;i++) {
    10. var divtarget = $ (' # ' +divs[i]);
    11. if (divtarget) {
    12. Divtarget.remove ();
    13. }
    14. }
    15. }
    16. });

Duplicate submission of form in Easyui tab-loaded page

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.