gpt4 book ai didi

jQuery序列化添加了名为 '_'(下划线)的附加字段

转载 作者:行者123 更新时间:2023-12-01 04:36:47 26 4
gpt4 key购买 nike

我使用:

$.getJSON('addRecord.php', $('#addRecord').serialize())

通过 AJAX 将 JSON 数据传递给 php 函数。然而,除了表单的字段之外,我还得到一个名为“_”的字段,尽管我没有对表单执行任何操作。所有表单字段都有名称和 ID,命令后面没有太多内容。

这是以下形式的代码:

<form id='addRecord'>
<div class='form-group' id='coTypeIdD'>
<label for='coTypeId'>Type</label>
<input type='text' class='form-control' id='coTypeId' name='coTypeId' placeholder='Type'>
<small id='coTypeIdM' class='text-danger'></small>
</div>
<div class='form-group' id='coAccountIdD'>
<label for='coAccountId'>Account</label>
<input type='text' class='form-control' id='coAccountId' name='coAccountId' placeholder='Account'>
<small id='coAccountIdM' class='text-danger'></small>
</div>
<div class='form-group' id='coIsPrimaryD'>
<label for='coIsPrimary'>Primary?</label>
<input type='text' class='form-control' id='coIsPrimary' name='coIsPrimary' placeholder='Primary?'>
<small id='coIsPrimaryM' class='text-danger'></small>
</div>
<div class='form-group' id='coDescriptionD'>
<label for='coDescription'>Description</label>
<input type='text' class='form-control' id='coDescription' name='coDescription' placeholder='Description'>
<small id='coDescriptionM' class='text-danger'></small>
</div>
<div class='form-group' id='coUserD'>
<label for='coUser'>User</label>
<input type='text' class='form-control' id='coUser' name='coUser' placeholder='User'>
<small id='coUserM' class='text-danger'></small>
</div>
<div class='form-group' id='coSalutationD'>
<label for='coSalutation'>Salutation</label>
<input type='text' class='form-control' id='coSalutation' name='coSalutation' placeholder='Salutation'>
<small id='coSalutationM' class='text-danger'></small>
</div>
<div class='form-group' id='coFirstNameD'>
<label for='coFirstName'>First Name</label>
<input type='text' class='form-control' id='coFirstName' name='coFirstName' placeholder='First Name'>
<small id='coFirstNameM' class='text-danger'></small>
</div>
<div class='form-group' id='coLastNameD'>
<label for='coLastName'>Last Name</label>
<input type='text' class='form-control' id='coLastName' name='coLastName' placeholder='Last Name'>
<small id='coLastNameM' class='text-danger'></small>
</div>
<div class='form-group' id='coTitleD'>
<label for='coTitle'>Title</label>
<input type='text' class='form-control' id='coTitle' name='coTitle' placeholder='Title'>
<small id='coTitleM' class='text-danger'></small>
</div>
<div class='form-group' id='coDepartmentIdD'>
<label for='coDepartmentId'>Department</label>
<input type='text' class='form-control' id='coDepartmentId' name='coDepartmentId' placeholder='Department'>
<small id='coDepartmentIdM' class='text-danger'></small>
</div>
<div class='form-group' id='coPreferredCommunicationD'>
<label for='coPreferredCommunication'>Preferred Communication</label>
<input type='text' class='form-control' id='coPreferredCommunication' name='coPreferredCommunication' placeholder='Preferred Communication'>
<small id='coPreferredCommunicationM' class='text-danger'></small>
</div>
<div class='form-group' id='coPhoneD'>
<label for='coPhone'>Extension</label>
<input type='text' class='form-control' id='coPhone' name='coPhone' placeholder='Extension'>
<small id='coPhoneM' class='text-danger'></small>
</div>
<div class='form-group' id='coEmailD'>
<label for='coEmail'>Email</label>
<input type='text' class='form-control' id='coEmail' name='coEmail' placeholder='Email'>
<small id='coEmailM' class='text-danger'></small>
</div>
<div class='form-group' id='coMobileD'>
<label for='coMobile'>Mobile </label>
<input type='text' class='form-control' id='coMobile' name='coMobile' placeholder='Mobile '>
<small id='coMobileM' class='text-danger'></small>
</div>
<div class='form-group' id='coSkypeD'>
<label for='coSkype'>coSkype</label>
<input type='text' class='form-control' id='coSkype' name='coSkype' placeholder='coSkype'>
<small id='coSkypeM' class='text-danger'></small>
</div>
<div class='form-group' id='coFaxD'>
<label for='coFax'>coFax</label>
<input type='text' class='form-control' id='coFax' name='coFax' placeholder='coFax'>
<small id='coFaxM' class='text-danger'></small>
</div>
<div class='form-group' id='coPhone2D'>
<label for='coPhone2'>Alternate Phone</label>
<input type='text' class='form-control' id='coPhone2' name='coPhone2' placeholder='Alternate Phone'>
<small id='coPhone2M' class='text-danger'></small>
</div>
<div class='form-group' id='coBirthdateD'>
<label for='coBirthdate'>Birthday</label>
<input type='text' class='form-control' id='coBirthdate' name='coBirthdate' placeholder='Birthday'>
<small id='coBirthdateM' class='text-danger'></small>
</div>
</form>

这是我在 PHP 中转储 $_GET 时得到的结果:

dump of $_GET

最佳答案

_ 字段由 jQuery 自动添加,以防止缓存数据。 $.getJSON() 方法是预先配置的,因此您无法更改其行为,但如果您想禁用缓存,可以使用 $.ajax() 方法。只需将其 cache 属性设置为 false

这是jQuery's docs for the cache property的解释:

It works by appending "_={timestamp}" to the GET parameters.

关于jQuery序列化添加了名为 '_'(下划线)的附加字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50722860/

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