Dynamically add form fields with jquery not posting

流过昼夜 提交于 2019-12-06 19:44:27

Submitting your form with a standard 'submit' button will not work in this case. The submit button does not take the formfields in account that are created after page load.

You'll have to write a submit handler that serializes your data and sends it to the server.

Try something like this:

$('#yourFormID').on('submit', function(e) {
    //prevent the default submithandling
    e.preventDefault();
    //send the data of 'this' (the matched form) to yourURL
    $.post('yourURL', $(this).serialize());
});

serverside you now have the $_POST variable filled with the keys and values.

You can also inspect the data that is send in firebug or any other webdeveloper tool.

EDIT:

I have altered your fiddle to work with my code:

http://jsfiddle.net/34rYv/67/

I have wrapped a <form></form> around your inputs and added a <input type='submit' /> button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!