admin管理员组文章数量:1400783
Using either Javascript and/or Jquery how can I append POST data to a form to submit. I have in my server side code that will check to see if the post data dictionary contains a certain key.
I already have a form in the code. So I would just like to use javascript to add a new key to the POST data.
Using either Javascript and/or Jquery how can I append POST data to a form to submit. I have in my server side code that will check to see if the post data dictionary contains a certain key.
I already have a form in the code. So I would just like to use javascript to add a new key to the POST data.
Share Improve this question asked Aug 6, 2012 at 20:21 Christopher HChristopher H 2,1946 gold badges24 silver badges31 bronze badges 1- Both the answers from Jarry and Fabrizio will get you started in the right direction. – davidethell Commented Aug 6, 2012 at 20:31
3 Answers
Reset to default 3quick example
you can add hidden inputs, for example:
var yourValue = 123;
$('form').append('<input type="hidden" id="yourData" name="yourData" value="'+ yourValue +'"/>');
so you get:
<input type="hidden" id="yourData" name="yourData" value="123"/>
and when you do the submit you are sending "yourData"
with jQuery:
var $input = $('<input>').attr(
{
type: 'hidden',
id: 'input_id',
name: 'input_name',
value: 'input_value'
}).appendTo('#form_name');
$('#form_name').submit();
is this what you were trying to do?
try to intercept the submit event and:
- serialize the form, add what you need to add and use the
$.post(url, data, function(){});
function. - inject the form with extra hidden input fields and then submit it via jquery
本文标签: jqueryAppend POST data javascriptStack Overflow
版权声明:本文标题:jquery - Append POST data javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744239695a2596728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论