ので、私は別のものにページをロードしています、すべてが正常に動作しますが、コントローラの負荷ではない:私は、スクリプトやCSSをロードしています コントローラCodeIgniterのでjqueryの/アヤックスで到達可能とブートストラップテンプレート
デフォルトのページコードとこれが問題かもしれませんが、私はそれが何であるか把握することはできません。 「リソースをロードできませんでした:サーバーは404(Not Found)」というステータスで応答しました。
マイビューコード:
<link href="<?php echo base_url('assets/datatables/css/dataTables.bootstrap.css')?>" rel="stylesheet">
<div class="container">
<button class="btn btn-success" onclick="add_etudiant()"><i class="glyphicon glyphicon-plus"></i> Ajouter un étudiant</button>
<br />
<br />
<table id="table_id" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Matricule</th>
<th>Nom</th>
<th>Prénom</th>
<th>E-mail</th>
<th>Date de naissance</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($etudiant as $row){?>
<tr>
<td><?php echo $row->matricule;?></td>
<td><?php echo $row->nom;?></td>
<td><?php echo $row->prenom;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->datenaiss;?></td>
<td>
<button class="btn btn-warning" onclick="edit_etudiant(<?php echo $row->matricule;?>)"><i class="glyphicon glyphicon-pencil"></i></button>
<button class="btn btn-danger" onclick="delete_etudiant(<?php echo $row->matricule;?>)"><i class="glyphicon glyphicon-remove"></i></button>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<script src="<?php echo base_url('assets/datatables/js/jquery.dataTables.min.js')?>"></script>
<script src="<?php echo base_url('assets/datatables/js/dataTables.bootstrap.js')?>"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table_id').DataTable();
});
var save_method; //for save method string
var table;
function add_etudiant()
{
save_method = 'add';
$('#form')[0].reset(); // reset form on modals
$('#modal_form').modal('show'); // show bootstrap modal
$('.modal-title').text('Ajouter un étudiant'); // Set Title to Bootstrap modal title
}
function save()
{
var url;
if(save_method == 'add')
{
url = "<?php echo site_url('index.php/etudiant/etudiant_add')?>";
}
else
{
url = "<?php echo site_url('index.php/book/book_update')?>";
}
// ajax adding data to database
$.ajax({
url : url,
type: "POST",
data: $('#form').serialize(),
dataType: "JSON",
success: function(data)
{
//if success close modal and reload ajax table
$('#modal_form').modal('hide');
location.reload();// for reload a page
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding/update data');
}
});
}
</script>
<div class="modal fade" id="modal_form" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title">Book Form</h3>
</div>
<div class="modal-body form">
<form action="#" id="form" class="form-horizontal">
<input type="hidden" value="" name="book_id"/>
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-3">Matricule</label>
<div class="col-md-9">
<input name="book_isbn" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Nom</label>
<div class="col-md-9">
<input name="book_title" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Prénom</label>
<div class="col-md-9">
<input name="book_author" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">E-mail</label>
<div class="col-md-9">
<input name="book_category" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Date de naissance</label>
<div class="col-md-9">
<input name="book_category" class="form-control" type="text">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="btnSave" onclick="save()" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
私のコントローラコード:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('etudiant_model');
}
public function index()
{
$this->data['etudiant']=$this->etudiant_model->get_all_etudiant();
}
public function etudiant_add()
{
$data = array(
'matricule' => $this->input->post('matricule'),
'nom' => $this->input->post('nom'),
'prenom' => $this->input->post('prenom'),
'email' => $this->input->post('email'),
'datenaiss' => $this->input->post('datenaiss')
);
$insert = $this->etudiant_model->etudiant_add($data);
echo json_encode(array("status" => TRUE));
}
enter code here
public function etudiant_edit($id)
{
$data = $this->etudiant_model->get_by_id($id);
echo json_encode($data);
}
public function etudiant_update()
{
$data = array(
'matricule' => $this->input->post('matricule'),
'nom' => $this->input->post('nom'),
'prenom' => $this->input->post('prenom'),
'email' => $this->input->post('email'),
'datenaiss' => $this->input->post('datenaiss')
);
$this->etudiant_model->etudiant_update(array('matricule' => $this->input->post('matricule')), $data);
echo json_encode(array("status" => TRUE));
}
public function etudiant_delete($id)
{
$this->etudiant_model->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
}
エラーメッセージは明確ではないと私は理解することはできませんので、あなたがこの上で私を助けてくださいそれ!
リソース(js、css)はそのメッセージを表示していますか? – kishor10d
jqueryの場合:http://localhost/ajax_crud_datatables/index.php/index.php/etudiant/etudiant_addリソースの読み込みに失敗しました:サーバが404のステータス(Not Found)で応答しました –
余分な '' 'index.php'あなたのURLに追加されました。 ajaxの代わりに '' 'base_url()' '' '' 'site_url()' ''を使用してください。 – kishor10d