gpt4 book ai didi

javascript - 发送 FORM POST 之前删除参数

转载 作者:行者123 更新时间:2023-12-03 03:53:18 25 4
gpt4 key购买 nike

我有一个页面,其中包含一个用 C# 制作的表单,该页面上有几个 HTML 元素。单击按钮时,我正在使用 jQuery 并添加隐藏字段,而不是将表单提交到外部域。现在的问题是,它正在发送我不需要的所有参数。有什么方法可以只发送我需要的参数。我只想在正文中发送参数。

有没有办法在添加参数之前清除表单参数

jQuery 代码

$("#aspnetForm").attr("action", "www.example.com");
$("#aspnetForm").attr("method", "post");
var params = a.split('?')[1].split('&'); /*custom string with key/value and sperated with & */
$.each(params, function (index) {
var paramsV = params[index].split('=');
$("#aspnetForm").append('<input type="hidden" name="' + paramsV[0] + '" value="' + paramsV[1] + '" /> ');
});
$("#aspnetForm").submit();

在我的表单中动态添加了 50 多个 HTML 元素,并且每次加载时它都有不同的 id。所以我无法在 Jquery 或 javascript 中禁用这些元素

最佳答案

我正在使用 SharePoint 2013,它有自己的母版页,其中添加了许多我无法控制的元素,因此我无法单独禁用它们。

我所做的是动态创建表单添加所需参数,然后提交它。

希望对大家有帮助

$("#frm").remove(); /** remove extra frm before creating it **/
var frm = $('<form id="frm" action="' + _url + '" method="POST"></form>');
var params = a.split('?')[1].split('&'); /*custom string with key/value and sperated with & */
$.each(params, function (index) {
var paramsV = params[index].split('=');
frm.append('<input type="hidden" name="' + paramsV[0] + '" value="' + paramsV[1] + '" /> ');
});
frm.appendTo(document.body).submit();

关于javascript - 发送 FORM POST 之前删除参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45081147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com