duanci6484 2016-10-11 17:25
浏览 68

HTML形式的数组仅在使用var_dump()进行检查时产生第一个结果

Here is the HTML and jQuery that produces the form (all it does is allows users to create another input field that has the same names: skillName[] and skillLevel[]):

$(document).ready(function() {
  var max_fields = 100;
  var wrapper = $(".wrapper");
  var add_button = $(".new-skill-field");

  var i = 1;
  $(document).on("click", ".new-skill-field", function(e) {

    e.preventDefault();
    if (i < max_fields) {
      i++;
      $(wrapper).append('<div><label>Skill Name:</label><input type="text" name="skillName[]"><label>Skill Level:</label><input type="text" name="skillLevel[]" class="input-small"><button class="remove-skill">Remove This Skill</button><br></div>');
    }
  });

  $(wrapper).on("click", ".remove-skill", function(e) {
    e.preventDefault();
    $(this).parent('div').remove();
    i--;
  });
});
<script src="//code.jquery.com/jquery-3.1.1.min.js"></script>

<div class="wrapper">
  <div>
    <label>Skill Name:</label>
    <input type="text" name="skillName[]" id="skillName">
    <label>Skill Level:</label>
    <input type="text" name="skillLevel[]" id="skillLevel" class="input-small">
    <br>
  </div>
</div>
<button class="new-skill-field">Add Another Skill</button>

View on JSFiddle

Regardless of how many fields I create and enter values into, if my PHP script is nothing else but var_dump($_POST['skillName']), it only returns one value: the first input field. I know this works, as I have done this in the past. I just cannot figure out why this form, or perhaps this jQuery, is causing it to only pass one value in the array.

And yes, I do need the arrays to be coded in the form... there is no other way of passing the array to my class and have it do what I need it to.

</div>
  • 写回答

1条回答 默认 最新

  • douleng3463 2016-10-11 19:18
    关注

    Okay this is one of the weirdest things that has happened in my (albeit short) programming career... I didn't touch anything whatsoever in the code, I refreshed the page to check the HTTP Live Headers since I had cleared them. It randomly picked up the array, after refreshing the same code (on 3 different browsers on this computer, 2 on my MacBook, and on my phone). I honestly have no idea what is going on at this point, but it seems to be working... for now. Thanks for taking the time to try and help!

    Here's to hoping the problem doesn't arise again, because I have no clue what changed to cause it to pick up the array indices!

    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条