简体   繁体   English

在发送FORM POST之前删除参数

[英]Remove parameters before sending FORM POST

I have page with one form made in C# on the page there are several HTML elements. 我的页面上有一种用C#制成的表单,页面上有几个HTML元素。 On button click I am using jQuery and add hidden fields than I submit form to external domain. 在按钮上单击我正在使用jQuery并添加隐藏字段,而不是将表单提交到外部域。 Now the issue is, that it is sending all the parameters which I don't need. 现在的问题是,它正在发送我不需要的所有参数。 Is there any way that I can send only parameter that I need. 有什么方法可以只发送我需要的参数。 I want to send parameter only in body. 我只想在体内发送参数。

Is there way to clear form parameter before adding parameter 有没有办法在添加参数之前清除表单参数

jQuery Code 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();

There more than 50 HTML element are added dynamically in my form and at each load it have different id. 在我的表单中动态添加了50多个HTML元素,每次加载时都有不同的ID。 So I cannot disable those element in Jquery or javascript 所以我不能在Jquery或javascript中禁用那些元素

Some people are very rude to down vote despite giving proper explanation. 尽管给出了适当的解释,但有些人还是很不赞成。

I am using SharePoint 2013, it have its own master page where it add lot of elements which I don't have control, so I cannot individually disable them. 我正在使用SharePoint 2013,它具有自己的母版页,其中添加了许多我无法控制的元素,因此无法单独禁用它们。

I will thank you to Krishna for pointing to correct direction. 我要感谢克里希纳指出正确的方向。

His answer for ajax POST cannot help as I got error No 'Access-Control-Allow-Origin' header is present on the requested resource. 他对ajax POST的回答无济于事,因为我收到错误消息请求的资源上没有'Access-Control-Allow-Origin'标头。 Origin ' . 起源' I don't have control over other domain, So I cannot use his answer. 我无法控制其他域,因此无法使用他的答案。

So what I did is I created dynamically form add required parameter and then submit it. 所以我要做的是动态创建表单,添加必需的参数,然后提交。

Hope it can help somebody 希望它可以帮助某人

$("#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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM