且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery输入具有相同的名称和方括号

更新时间:2023-02-18 16:15:39

不是你问题的确切答案,但有一种更简单的方法可以做到这一点。

Not an exact answer to your question, but there is an easier way to do this.

包裹你的表单中的输入字段并生成 on-submit -event。返回此事件为false,因此实际上并未提交。

Wrap your input-fields in a form and make an on-submit-event. Return this event false so it's not actually submitted.

这就是诀窍。在将事件返回false之前,请执行ajax-request。给表单一个id并使用seralize-method创建一个json-string。

Here's the trick. Before you return the event false, do the ajax-request. Give the form an id and use the seralize-method to make a json-string.

[...]
data: $('#formIDGoesHere').serialize(),
[...]

如果您将此文件作为POST变量发布到PHP文件中,则所有值都不可用,就像它们通常位于 $ _ POST 中一样。

If you post this to your PHP file as POST-variables, all your values are not available like they normally would be in $_POST.