选择“加载 XMLHTTP 不会随表单一起发送”


select loaded with xmlhttp doesn't get send with form

我正在为一个小型书签网站开发一个chrome扩展程序。扩展弹出窗口使用浏览器的当前 URL、标题、所选文本填充表单。问题是,我使用javascripts xmlhttp调用Web服务器在表单中加载了一个带有选择选项的div。

当我发送表单

时,选择选项中的选定选项不会与表单的其余部分一起发送。

形式:

<form action="removed" method="post" enctype="multipart/form-data" name="popup_form">
        <span class="input_header">Titel</span>
        <input class="calendar_add_form_Date" type="text" name="title">
        <span class="input_header">URL</span>
        <input class="calendar_add_form_Date" type="text" name="url">
                <span class="input_header">NOTE</span>
      <textarea id="note" name="note" style="height: 60px;"></textarea>
      <span class="input_header">Tags</span>
      <input class="calendar_add_form_Date" type="text" id="tags" name="tags">
      <div id="url"></div>

</div>
</div>
<div id="popup_footer"><input class="btn btn_blue" style="" value="&nbsp;Add&nbsp;" type="submit"/>
<div id="sets">
</div>

稍后阅读

javascript 调用:

function loadSets()
{
var xmlhttp;
  xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange=function()
  {
    if(xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("sets").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("POST","link[1]",true);
  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlhttp.send();
}

链接[1]输出以下内容:

<select name="sets">
<option value="1">One</option>
<option value="2">Two</option>
</select>

我在你的HTML中看到</div> s比<div> s多。我怀疑您正在生成的 HTML 是无效的,并且 <form> 元素被隐式关闭的时间比您希望的要早——因此,您注入的元素不在表单中。

在Chrome的"Inspect Element"中查看生成的DOM树可能会有所启发。