javascript - 导致 IE 中出现问题的表单名称属性

标签 javascript jquery html 2checkout

当我将表单值提交到 2check out 支付网关时,我收到 PE101 错误(即要求值未通过)。 调试我的代码后,我发现 PE101 错误仅在 IE 中引起问题,因为 name 属性具有空值。 相同的代码在 Chrome 中工作,但当我在 IE、Edge 中尝试时,它导致了问题。 谁能告诉我为什么 2check 支付网关不采用 IE 中没有名称属性的表单值。

              $("#idNavPremimum").click(function() {
                alert("k");
                $("input[name*='quantity']").val("88");
                $("input[name*='li_0_price']").val("99");
                $("input[name*='email']").val("uday.a@gmail.com");
                $("#payment").submit();
        
              });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <form id="payment" action='https://sandbox.2checkout.com/checkout/purchase' method='post'>
              <div class="form-group">

                <label for="quantity" class="col-md-1 control-label">No. of users</label>
                <div class="col-md-2">
                  <!----------------------This control causing the issue--------------------->
                  <input type="text" maxlength="3" class="form-control specialCharRestrict" id="quantity" name="">
                  <!----------------------This control causing the issue ends--------------------->
                </div>
                <label for="ddlPriceCalcMonths" class="col-md-1 control-label">No. of months</label>
                <div class="col-md-2">
                  <select id="ddlPriceCalcMonths" class="form-control clsPriceValDetails" disabled>
                    <option value="1">1</option>
                    <option value="3">3</option>
                    <option value="6">6</option>
                    <option value="12">12</option>
                  </select>
                </div>
                <label for="txtTotalPrice" class="col-md-1 control-label">Total price</label>
                <div class="col-md-2">
                  <input type="text" class="form-control clsPriceVal" id="txtTotalPrice" readonly/>
                </div>
                <!--<input type='hidden' name='sid' value='901286127' />-->
                <input type='hidden' name='sid' value='901286127' />
                <input type='hidden' name='mode' value='2CO' />
                <input type="hidden" name="currency_code" value="USD" />

                <input type='hidden' name='li_0_type' value='product'>
                <input type='hidden' name='li_0_name' value='Webstation Premium'>
                <input type='hidden' name='li_0_price' value='20'>
                <input type='hidden' name='li_0_quantity' value='2'>
                <input type='hidden' name='li_0_tangible' value='N'>
                <input type='hidden' name='email' value='uday.a@gmail.com'>
                <input type='hidden' name='fixed' value='Y' />
                <input type='hidden' name='x_receipt_link_url' value='http://webstation.osmosystems.com/' />

              </div>

            </form>
            <div class="form-group">
              <button class="button-style btnPos" type='button' data-toggle="modal" data-target="#divwebstationForm" id="idNavPremimum"><i class="fa fa-android fa-fw"></i> BUY NOW <i class="fa fa-cloud-download fa-fw"></i></button>
            </div>

最佳答案

这是由于 IE 表单行为的实现造成的。

根据 MS specs对于文本等输入,name 参数是必需的。 提交表单时,IE 会考虑没有 name 属性的输入 - 这意味着这些输入包含在请求的 Content-Length header 中,并且 FormData 包含空行。

另一方面,Chrome、FF 如果遇到没有 name 的输入,它们就会忽略它。

总而言之 - 要使其在 IE 上运行,您需要添加 name 属性。

关于javascript - 导致 IE 中出现问题的表单名称属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38897427/

相关文章:

jquery - 等待 getJSON 响应

HTML 弹出页脚问题。 100%高度问题

javascript - 在 Javascript 中动态添加新表行

javascript - Google Maps API V3 读取 KML 文件

jquery - 向ajax启动函数发送参数

javascript - 动态添加项目到Packery。它到底是如何运作的?

javascript - 将新内容加载到 HTML 页面

javascript - 在模态中自动单击按钮

javascript - 无法访问vuejs中方法中的数据变量

javascript - 工厂中的 AngularJS $scope