【问题标题】:Can't load Jquery and dataTables无法加载 Jquery 和 dataTables
【发布时间】:2015-03-31 08:22:29
【问题描述】:

我尝试使用数据表,但它没有加载 JQuery 和数据表。我正在尝试使用此示例: https://datatables.net/examples/basic_init/alt_pagination.html 但数据表根本不加载,只有我的表。 我的代码是:

    <html>
<head>
 
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
 <link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.min.css" type="text/css"  />

<script src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>

<script type='text/javascript'>

	$(document).ready(function() {
    $('#example').dataTable( {
        "pagingType": "full_numbers"
    } );
} );
</script>
</head>
<body>
<br/><br/>
<?php
$survey_id = $this->uri->segment(3);

	echo "<div class='col-md-9'>";

echo '<table border="0" id="example" class="display" cellspacing="0" width="100%">';
 
echo validation_errors();

foreach ($survey as $row)
{	
	
	echo "<tr>";
	echo form_open('index/survey_fill/' .$survey_id );
    echo "<td class='col-md-9'>"; 
	echo "$row->question";
	
	echo "</td>";
	
	echo "</tr><tr><td>";  
	$data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => '5'
	);
	  echo "<input type='hidden' name='survey_id' value='$row->survey_id'>";
	echo "<input type='hidden' name='question_id' value='$row->question_id' />";
	echo form_radio($data);
	echo " 5";
	$data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => ' 4'
	);
	echo form_radio($data);
	echo " 4 ";
	echo "</td></tr><tr>";
  
}
   
    echo "</td></tr><tr><td>";
	
	$data=array(
		'name' => 'submit',
		'value' => 'send',
		'class' => 'btn btn-primary',
		 'id' => 'survey_submit'
	);
	echo form_submit($data);
	echo "</td></tr>";
	echo form_close();
	  	

    echo "</table>";
    
	echo "</div>";
	echo "</body>";
	echo "</html>";

我的代码有什么问题?

【问题讨论】:

标签: jquery datatables


【解决方案1】:

我修复了我的代码,现在它显示了数据表,来自我的服务的每个问题都在另一行,但是当我单击提交按钮时,它没有提交任何数据。 我现在的代码是:

<html>
<head>
 <link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.min.css" type="text/css"  />

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>

<script>

	$(document).ready(function() {
    $('#example').dataTable( {
        "pagingType": "simple",
        "lengthMenu": [[1], [1]]
    } );

} );

	
</script>
</head>
<body>
<br/><br/>
<?php
$survey_id = $this->uri->segment(3);
<table  id="example" >
  <thead>
      <tr><th>Въпрос</th></tr>
    </thead>
      
    <tbody>
    <?php
echo validation_errors();

foreach ($survey as $row)
{
	
	$row->question_id=$this->uri->segment(4);
	$question_id=$this->uri->segment(4);
	?>
	<tr>
	<?php 
	$attributes = array('id' => 'myform');
	echo form_open('index/survey_fill/' .$survey_id  , $attributes); ?>
   <td> 
	<?php echo "$row->question"; ?><br/>
	<?php echo "<input type='hidden' name='question_id' value='$row->question_id' />"; ?>
     $data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => '5'
	);
	   echo "<input type='hidden' name='survey_id' value='$row->survey_id'>"; ?>
	<?php echo "<input type='hidden' name='question_id' value='$row->question_id' />"; 
	 echo form_radio($data); 
	echo " 5 ";
	$data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => ' 4'
	);
	echo form_radio($data);
	echo "4 ";
?>
	</td></tr>
  
<?php 
}
?>
   
    <tr><td>
  	<?php 
?>
	<input type="submit" id="button" name = "submit" value="Submit"> 
	</td></tr>
	<?php echo form_close(); ?>
	
	
	</tbody>
    </table>
    

	
	</body>
	</html>

我的模型是:

$answers=($this->input->post('answer'));

        if (null !==($this->input->post('submit'))) {
            $date = new DateTime("now"); 

            foreach($answers as $question_id=>$answer)
            {
                $data = array(
                    'user_id'=>$this->session->userdata['user_id'],
                    'question_id'=>$question_id,
                    'answer'=>$answer,              
                    'created_at'=>$date->format('Y-m-d H:i:s')
                );
$this->db->insert('survey_answers', $data);
                
            }
              if($this->db->affected_rows() > 0)
            {
                 
                return true;
            } 
            return false;
        }

【讨论】:

    猜你喜欢
    • 2014-12-15
    • 1970-01-01
    • 2011-11-18
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 2013-05-15
    相关资源
    最近更新 更多