簡體   English   中英

在.each()循環中多次提交表單,僅最后一次提交發送

[英]Submitting form multiple times in .each() loop, only last submit sending

我正在嘗試提交表單,然后更新一些值並再次提交。 但是,當我這樣做時,僅提交了LAST版本。 我收到Unsafe Javascript attempt to access frame with URL domain2.com from frame with URL domain1 . Domains, Protocols and Ports must match.遇到一個錯誤Unsafe Javascript attempt to access frame with URL domain2.com from frame with URL domain1 . Domains, Protocols and Ports must match. Unsafe Javascript attempt to access frame with URL domain2.com from frame with URL domain1 . Domains, Protocols and Ports must match.

表格代碼:

<form id="hiddenform" method="post" enctype="multipart/form-data" action="http://www.actonsoftware.com/acton/forms/userSubmit.jsp" accept-charset="UTF-8" target="tintest">

目標是id="tintest"的隱藏iframe

這是我的代碼:

var tbody = $("#vmMainPage table:first tbody");
    var lng = tbody[0].rows.length - 1;
    var mnstr = "items: ";
    $("#vmMainPage table:first tbody tr").each(function(i){ 
        if ((i>0) && (i<(lng-3))) {
            item = $(this).children("td").children("a").children("strong").html();
            // quantity = "
            console.log(item);
            $("#hiddenform input#fld_0").val(item);
            var $tsta = "";
            for ( j=2; j<6; j++)
            {
                $tst = $("table:eq(2) tr:eq("+j+") td:eq(1)").html();
                $tsta = $tsta + $tst +", ";
            }
            $email = $("table:eq(2) tr:eq(6) td:eq(1)").html();
            $("#hiddenform input#fld_2").val($email+"_"+i);
            $("#hiddenform input#fld_1").val($tsta);
            $("#hiddenform").submit();
        }
    });

為確保您的請求不會互相干擾,您可以為每個請求創建一個iframe並將其定位。

這可以通過DOM var cnt = 0來完成;

var ifr = document.createElement("iframe");
ifr.name="ifr"+(cnt++);
ifr.style.display="none"
document.getElementById("iframeContainer").appendChild(ifr);
document.forms[0].target=ifr.name;
document.forms[0].submit()

或jQuery

cnt++
$("#iframeContainer").append('<iframe src="about:blank" name="ifr'+cnt+'"></iframe>');
$("#hiddenform").attr("target","ifr"+cnt);
$("#hiddenform").submit();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM