div不会出现。为什么?

时间:2017-05-15 08:12:46

标签: javascript php html

我创建了一个javascript +一个php页面。 php页面上的脚本将数据发送到我的sql数据库,但是没有在我的主页上显示结果。

这里是代码



function getVote(question_ID) {
  var option_ID = document.querySelector("input[id='option']:checked").value;
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function() {
    if (option_ID.readyState == 4 && option_ID.status == 200) {
      document.getElementById(poll).innerHTML = option_ID.responseText;

    }
  }
  xmlhttp.open("GET", "./core/vote.php?user_ID=" + user_ID + "&question_ID=" + question_ID + "&option_ID=" + option_ID, true);
  xmlhttp.send();

}

<div id="poll">
</div>
&#13;
&#13;
&#13;

更多代码

&#13;
&#13;
<div id="poll">
    	<form method="post" onsubmit='getVote(question_ID);' >
        <p><?php echo $question ['question_content']; ?></p>

        <p>

	<?php
	$poll_option_selection = "SELECT option_ID, option_content FROM poll_options WHERE question_ID='$question_ID'" ;
	$poll_option_result = mysqli_query ($connect,$poll_option_selection) ;
	foreach ($poll_option_result as $poll_option) { 
	$option_ID = $poll_option ['option_ID'] ;
	$option_content = $poll_option ['option_content'] ;
	?>
	<script type="text/javascript">
	var option_ID = <?php echo json_encode($option_ID) ; ?> ;
	</script>
	<input type="radio" id="option" value ='<?php echo $option_ID ?>'  required /> 
	<?php echo $option_content ?>
	</br>
	<?php
	}
	?>
	<input type="submit">
	</form>
	</div>
&#13;
&#13;
&#13;

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

应该是:

document.getElementById("poll").innerHTML=option_ID.responseText;

document.getElementById将参数(元素的id)作为字符串。